Skip to content

Commit 976707d

Browse files
authored
Merge pull request #215 from restackio/fix-pydantic-serialization
Fix pydantic serialization error
2 parents fa7e2d1 + 7d37f04 commit 976707d

File tree

7 files changed

+65
-16
lines changed

7 files changed

+65
-16
lines changed

agent_rag/src/agents/chat_rag.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
from datetime import timedelta
22

33
from pydantic import BaseModel
4-
from restack_ai.agent import NonRetryableError, agent, import_functions, log
4+
from restack_ai.agent import (
5+
NonRetryableError,
6+
agent,
7+
import_functions,
8+
log,
9+
)
510

611
with import_functions():
7-
from src.functions.llm_chat import LlmChatInput, Message, llm_chat
12+
from src.functions.llm_chat import (
13+
LlmChatInput,
14+
Message,
15+
llm_chat,
16+
)
817
from src.functions.lookup_sales import lookup_sales
918

1019

agent_rag/src/functions/llm_chat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ async def llm_chat(function_input: LlmChatInput) -> ChatCompletion:
5353
raise NonRetryableError(error_message) from e
5454
else:
5555
log.info("llm_chat function completed", response=response)
56-
return response
56+
return response.model_dump()

agent_todo/src/agents/agent_todo.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
from datetime import timedelta
22

33
from pydantic import BaseModel
4-
from restack_ai.agent import NonRetryableError, agent, import_functions, log
5-
6-
from src.workflows.todo_execute import TodoExecute, TodoExecuteParams
4+
from restack_ai.agent import (
5+
NonRetryableError,
6+
agent,
7+
import_functions,
8+
log,
9+
)
10+
11+
from src.workflows.todo_execute import (
12+
TodoExecute,
13+
TodoExecuteParams,
14+
)
715

816
with import_functions():
917
from openai import pydantic_function_tool
1018

11-
from src.functions.llm_chat import LlmChatInput, Message, llm_chat
12-
from src.functions.todo_create import TodoCreateParams, todo_create
19+
from src.functions.llm_chat import (
20+
LlmChatInput,
21+
Message,
22+
llm_chat,
23+
)
24+
from src.functions.todo_create import (
25+
TodoCreateParams,
26+
todo_create,
27+
)
1328

1429

1530
class MessagesEvent(BaseModel):

agent_todo/src/functions/llm_chat.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
from openai.types.chat.chat_completion_message_tool_call import (
88
ChatCompletionMessageToolCall,
99
)
10-
from openai.types.chat.chat_completion_tool_param import ChatCompletionToolParam
10+
from openai.types.chat.chat_completion_tool_param import (
11+
ChatCompletionToolParam,
12+
)
1113
from pydantic import BaseModel
1214
from restack_ai.function import NonRetryableError, function, log
1315

@@ -62,4 +64,4 @@ async def llm_chat(function_input: LlmChatInput) -> ChatCompletion:
6264
raise NonRetryableError(error_message) from e
6365
else:
6466
log.info("llm_chat function completed", response=response)
65-
return response
67+
return response.model_dump()

agent_todo/src/workflows/todo_execute.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
from datetime import timedelta
22

33
from pydantic import BaseModel
4-
from restack_ai.workflow import NonRetryableError, import_functions, log, workflow
4+
from restack_ai.workflow import (
5+
NonRetryableError,
6+
import_functions,
7+
log,
8+
workflow,
9+
)
510

611
with import_functions():
712
from src.functions.get_random import RandomParams, get_random

agent_tool/src/agents/chat_tool_functions.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
from datetime import timedelta
22

33
from pydantic import BaseModel
4-
from restack_ai.agent import NonRetryableError, agent, import_functions, log
4+
from restack_ai.agent import (
5+
NonRetryableError,
6+
agent,
7+
import_functions,
8+
log,
9+
)
510

611
with import_functions():
712
from openai import pydantic_function_tool
813

9-
from src.functions.llm_chat import LlmChatInput, Message, llm_chat
10-
from src.functions.lookup_sales import LookupSalesInput, lookup_sales
14+
from src.functions.llm_chat import (
15+
LlmChatInput,
16+
Message,
17+
llm_chat,
18+
)
19+
from src.functions.lookup_sales import (
20+
LookupSalesInput,
21+
lookup_sales,
22+
)
1123

1224

1325
class MessagesEvent(BaseModel):

agent_tool/src/functions/llm_chat.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
from openai.types.chat.chat_completion_message_tool_call import (
88
ChatCompletionMessageToolCall,
99
)
10-
from openai.types.chat.chat_completion_tool_param import ChatCompletionToolParam
10+
from openai.types.chat.chat_completion_tool_param import (
11+
ChatCompletionToolParam,
12+
)
1113
from pydantic import BaseModel
1214
from restack_ai.function import NonRetryableError, function, log
1315

@@ -52,11 +54,15 @@ async def llm_chat(function_input: LlmChatInput) -> ChatCompletion:
5254
Message(role="system", content=function_input.system_content or "")
5355
)
5456

55-
return client.chat.completions.create(
57+
result = client.chat.completions.create(
5658
model=function_input.model or "gpt-4o-mini",
5759
messages=function_input.messages,
5860
tools=function_input.tools,
5961
)
62+
63+
log.info("llm_chat function completed", result=result)
64+
65+
return result.model_dump()
6066
except Exception as e:
6167
error_message = f"LLM chat failed: {e}"
6268
raise NonRetryableError(error_message) from e

0 commit comments

Comments
 (0)