Skip to content

Commit

Permalink
fixes tests to work with as_graph
Browse files Browse the repository at this point in the history
  • Loading branch information
filipeximenes committed Sep 11, 2024
1 parent 59c8950 commit 34056e9
Show file tree
Hide file tree
Showing 9 changed files with 931 additions and 52 deletions.
4 changes: 2 additions & 2 deletions django_ai_assistant/langchain/chat_message_histories.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def add_messages(self, messages: Sequence[BaseMessage]) -> None:
messages: A list of BaseMessage objects to store.
"""
with transaction.atomic():
existing_messages = self.messages
existing_messages = self.get_messages()

messages_to_create = [m for m in messages if m not in existing_messages]

Expand All @@ -99,7 +99,7 @@ async def aadd_messages(self, messages: Sequence[BaseMessage]) -> None:
Args:
messages: A list of BaseMessage objects to store.
"""
existing_messages = self.messages
existing_messages = await self.aget_messages()

messages_to_create = [m for m in messages if m not in existing_messages]

Expand Down
125 changes: 125 additions & 0 deletions tests/cassettes/test_views/test_create_thread_message.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,129 @@ interactions:
status:
code: 200
message: OK
- request:
body: '{"messages": [{"content": "You are a temperature bot. Today is 2024-06-09.",
"role": "system"}, {"content": "Hello, what is the temperature in SF right now?",
"role": "user"}], "model": "gpt-4o", "n": 1, "stream": false, "temperature":
1.0, "tools": [{"type": "function", "function": {"name": "fetch_current_temperature",
"description": "Fetch the current temperature data for a location", "parameters":
{"type": "object", "properties": {"location": {"type": "string"}}, "required":
["location"]}}}, {"type": "function", "function": {"name": "fetch_forecast_temperature",
"description": "Fetch the forecast temperature data for a location", "parameters":
{"type": "object", "properties": {"location": {"type": "string"}, "dt_str":
{"description": "Date in the format ''YYYY-MM-DD''", "type": "string"}}, "required":
["location", "dt_str"]}}}]}'
headers:
accept:
- application/json
accept-encoding:
- gzip, deflate
authorization:
- DUMMY
connection:
- keep-alive
content-length:
- '841'
content-type:
- application/json
host:
- api.openai.com
user-agent:
- OpenAI/Python
method: POST
uri: https://api.openai.com/v1/chat/completions
response:
body:
string: !!binary |
H4sIAAAAAAAAAwAAAP//bFJNj5swFLzzK6x3DhWQwO5yS3eXrdRLtZWqqE2FXpwHofVXbVOVRvnv
FR9J2KgcLGuGmXke+xgwBs0ecgb8gJ5LI8J19iH6+LXT6lVEu/i56Db1+91v3CR32UbAolfo3Q/i
/qx6x7U0gnyj1UhzS+ipd43vkixK77OHbCCk3pPoZbXx4UqHSZSswigN4+UkPOiGk4OcfQsYY+w4
rP2Iak9/IGfR4oxIcg5rgvzyE2NgtegRQOca51F5WFxJrpUn1U+tWiFmhNdalByFuAaP33G2v/aE
QpTpy6sqvsju+Qn1g335Zf4ma1N8KmZ5o3VnhoGqVvFLPzP+guc3YYyBQjlqyfNDyVtrSfnSkzRk
0beWbswYA7R1K0n5/iBw3ILQHHv7LeRb+IyKFRYVbxzXC/a43sIJ3jicgv/tv8+qslS1DsXU4YSf
LpcidG2s3rmbjqFqVOMOpSV0w1nnlQfntCEH2je3CsZqaXzp9U9SvW0cr0ZXuD66GXs/kV57FDN8
mQTTnOA650mWVaNqssY2w4uAypRJmiUrpCWmEJyCfwAAAP//AwDHlhryGgMAAA==
headers:
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Type:
- application/json
Date: Sun, 09 Jun 2024 23:39:08 GMT
Server: DUMMY
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
access-control-expose-headers:
- X-Request-ID
status:
code: 200
message: OK
- request:
body: '{"messages": [{"content": "You are a temperature bot. Today is 2024-06-09.",
"role": "system"}, {"content": "Hello, what is the temperature in SF right now?",
"role": "user"}, {"content": null, "role": "assistant", "tool_calls": [{"type":
"function", "id": "call_5GRnFVmyEDao9rGqpz2ApFPF", "function": {"name": "fetch_current_temperature",
"arguments": "{\"location\": \"San Francisco, CA\"}"}}]}, {"content": "32 degrees
Celsius", "role": "tool", "tool_call_id": "call_5GRnFVmyEDao9rGqpz2ApFPF"}],
"model": "gpt-4o", "n": 1, "stream": false, "temperature": 1.0, "tools": [{"type":
"function", "function": {"name": "fetch_current_temperature", "description":
"Fetch the current temperature data for a location", "parameters": {"type":
"object", "properties": {"location": {"type": "string"}}, "required": ["location"]}}},
{"type": "function", "function": {"name": "fetch_forecast_temperature", "description":
"Fetch the forecast temperature data for a location", "parameters": {"type":
"object", "properties": {"location": {"type": "string"}, "dt_str": {"description":
"Date in the format ''YYYY-MM-DD''", "type": "string"}}, "required": ["location",
"dt_str"]}}}]}'
headers:
accept:
- application/json
accept-encoding:
- gzip, deflate
authorization:
- DUMMY
connection:
- keep-alive
content-length:
- '1163'
content-type:
- application/json
cookie:
- DUMMY
host:
- api.openai.com
user-agent:
- OpenAI/Python
method: POST
uri: https://api.openai.com/v1/chat/completions
response:
body:
string: !!binary |
H4sIAAAAAAAAAwAAAP//VJDNbsIwEITveYqVzwkKIQHKjaK2VOJQFW5VhYzZELeJ17I3EgjxTn2G
PlmVEH568WE+z2h2jgGA0FsxAaEKyaqyZTQdzuPF5mWVL5ZyeiiyVZzu5evj0+GN3ucibBy0+ULF
F1dPUWVLZE3mjJVDydik9kfJMM7Gw4dRCyraYtnYdpajlKIkTtIozqL+oDMWpBV6MYGPAADg2L5N
RbPFvZhAHF6UCr2XOxST6ycA4ahsFCG9156lYRHeoCLDaNrWqwJB1c6hYWCsLDrJtUPQBpbSwLOT
RmmvKITZFLSHQfL7M+vdhznMay+bW0xdlp1+urYraWcdbXzHr3qujfbF2qH0ZJomnsmKlp4CgM92
hfrfYcI6qiyvmb7RNIH9ND3nidvu97SDTCzLOz0bB11D4Q+esVrn2uzQWafPo+R2nWTDJJU4kJkI
TsEfAAAA//8DAFmF1AcdAgAA
headers:
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Type:
- application/json
Date: Sun, 09 Jun 2024 23:39:08 GMT
Server: DUMMY
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
access-control-expose-headers:
- X-Request-ID
status:
code: 200
message: OK
version: 1
125 changes: 125 additions & 0 deletions tests/cassettes/test_views/test_delete_thread_message.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,129 @@ interactions:
status:
code: 200
message: OK
- request:
body: '{"messages": [{"content": "You are a temperature bot. Today is 2024-06-09.",
"role": "system"}, {"content": "Hello, what is the temperature in SF right now?",
"role": "user"}], "model": "gpt-4o", "n": 1, "stream": false, "temperature":
1.0, "tools": [{"type": "function", "function": {"name": "fetch_current_temperature",
"description": "Fetch the current temperature data for a location", "parameters":
{"type": "object", "properties": {"location": {"type": "string"}}, "required":
["location"]}}}, {"type": "function", "function": {"name": "fetch_forecast_temperature",
"description": "Fetch the forecast temperature data for a location", "parameters":
{"type": "object", "properties": {"location": {"type": "string"}, "dt_str":
{"description": "Date in the format ''YYYY-MM-DD''", "type": "string"}}, "required":
["location", "dt_str"]}}}]}'
headers:
accept:
- application/json
accept-encoding:
- gzip, deflate
authorization:
- DUMMY
connection:
- keep-alive
content-length:
- '841'
content-type:
- application/json
host:
- api.openai.com
user-agent:
- OpenAI/Python
method: POST
uri: https://api.openai.com/v1/chat/completions
response:
body:
string: !!binary |
H4sIAAAAAAAAA2xSXWvbMBR9968Q9zkejuOkmd+SQbsW+jFGS8cyjKpc29r0hXQNDSH/vfgjiRvm
ByHO8Tnn6kj7iDGQW8gZiJqT0E7Fq8X35J6qm3XlQnr7+LKWr4/16/PtnUpLDZNWYd/+oqCj6ouw
2ikkaU1PC4+csHWdXqWLZL5cfF12hLZbVK2schRnNk6TNIuTeTydDcLaSoEBcvY7Yoyxfbe2I5ot
vkPOkskR0RgCrxDy00+MgbeqRYCHIANxQzA5k8IaQtNObRqlRgRZqwrBlToH999+tD/3xJUqrnf2
nSfu4cfTw2q9usnWv8L2rvL3o7zeeue6gcrGiFM/I/6E5xdhjIHhutciiboQjfdoqCDUDj2nxuOF
GWPAfdVoNNQeBPYbUFbw1n4D+QZ+csOuPTdCBmEn7NtqAwf45HCI/rf/M6rKY9kEroYOB/xwuhRl
K+ftW7joGEppZKgLjzx0Zx1XHh3TuhxoPt0qOG+1o4LsPzSt7XSa9a5wfnQjdjmQZImrET5Lo2FO
CLtAqItSmgq987J7EVC6Ip0v0ozjjM8hOkQfAAAA//8DADocc08aAwAA
headers:
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Type:
- application/json
Date: Sun, 09 Jun 2024 23:39:08 GMT
Server: DUMMY
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
access-control-expose-headers:
- X-Request-ID
status:
code: 200
message: OK
- request:
body: '{"messages": [{"content": "You are a temperature bot. Today is 2024-06-09.",
"role": "system"}, {"content": "Hello, what is the temperature in SF right now?",
"role": "user"}, {"content": null, "role": "assistant", "tool_calls": [{"type":
"function", "id": "call_Fyoxa0pNQPNABAG4BYsdJgrM", "function": {"name": "fetch_current_temperature",
"arguments": "{\"location\": \"San Francisco, CA\"}"}}]}, {"content": "32 degrees
Celsius", "role": "tool", "tool_call_id": "call_Fyoxa0pNQPNABAG4BYsdJgrM"}],
"model": "gpt-4o", "n": 1, "stream": false, "temperature": 1.0, "tools": [{"type":
"function", "function": {"name": "fetch_current_temperature", "description":
"Fetch the current temperature data for a location", "parameters": {"type":
"object", "properties": {"location": {"type": "string"}}, "required": ["location"]}}},
{"type": "function", "function": {"name": "fetch_forecast_temperature", "description":
"Fetch the forecast temperature data for a location", "parameters": {"type":
"object", "properties": {"location": {"type": "string"}, "dt_str": {"description":
"Date in the format ''YYYY-MM-DD''", "type": "string"}}, "required": ["location",
"dt_str"]}}}]}'
headers:
accept:
- application/json
accept-encoding:
- gzip, deflate
authorization:
- DUMMY
connection:
- keep-alive
content-length:
- '1163'
content-type:
- application/json
cookie:
- DUMMY
host:
- api.openai.com
user-agent:
- OpenAI/Python
method: POST
uri: https://api.openai.com/v1/chat/completions
response:
body:
string: !!binary |
H4sIAAAAAAAAA1SRS2vDMBCE7/4Vi85xcBw7r1swlFJoe2hoS0sJirJ21MiS0K6hJeS/FzvOoxcd
5tsZZleHCEDorViAUDvJqvYmXk7uk8fVtHr2WnERij1tZu8Pb0+vH7hvxKB1uM03Kj67hsrV3iBr
Z09YBZSMbepomk6SfDaZzzpQuy2a1lZ5jjMXp0maxUkej8a9cee0QhIL+IwAAA7d21a0W/wRC0gG
Z6VGIlmhWFyGAERwplWEJNLE0rIYXKFyltF2rVc7BNWEgJaBsfYYJDcBQVt4kRbugrRKk3IDKJag
CcYpbLEKiAQFGtINDW+TA5YNyXYx2xjT68dLVeMqH9yGen7RS2017dYBJTnb1iJ2XnT0GAF8dSdp
/m0pfHC15zW7Pdo2cJRlpzxx/YQbmveQHUtzq8+jvqGgX2Ks16W2FQYf9OlCpV+n+STNJI5lLqJj
9AcAAP//AwAgzy7tKgIAAA==
headers:
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Type:
- application/json
Date: Sun, 09 Jun 2024 23:39:08 GMT
Server: DUMMY
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
access-control-expose-headers:
- X-Request-ID
status:
code: 200
message: OK
version: 1
Loading

0 comments on commit 34056e9

Please sign in to comment.