Skip to content

Commit

Permalink
checkpoint: Function calling program fails. Needs investigation.
Browse files Browse the repository at this point in the history
  • Loading branch information
anirbanbasu committed Aug 9, 2024
1 parent 8940a63 commit 93b00d5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/coder_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
from llama_index.core.tools import ToolSelection, ToolOutput
from llama_index.core.workflow import Event

from pydantic import BaseModel
from typing_extensions import TypedDict

from llama_index.core.program import FunctionCallingProgram

from code_executor import CodeExecutor

Expand All @@ -41,6 +43,12 @@ class TestCase(TypedDict):
outputs: str


class CoderAgentOutput(BaseModel):
reasoning: str
pseudocode: str
code: str


class InputEvent(Event):
input: list[ChatMessage]
test_cases: list[TestCase] = None
Expand Down Expand Up @@ -68,6 +76,15 @@ def __init__(

self.tools = [FunctionTool.from_defaults(self.evaluate)]

self.pydantic_code_generator = FunctionCallingProgram.from_defaults(
output_cls=CoderAgentOutput,
llm=self.llm,
verbose=True,
prompt_template_str="{input}",
tool_choice=self.tools[0],
allow_parallel_tool_calls=True,
)

self.memory = ChatMemoryBuffer.from_defaults(llm=llm)
self.sources = []

Expand All @@ -90,6 +107,9 @@ async def handle_llm_input(self, ev: InputEvent) -> ToolCallEvent | StopEvent:
ic(ev)
chat_history = ev.input

ic(chat_history[-1].content)
pydantic_call = self.pydantic_code_generator(input=chat_history[-1].content)
ic(pydantic_call)
response = await self.llm.achat_with_tools(
self.tools, chat_history=chat_history
)
Expand Down

0 comments on commit 93b00d5

Please sign in to comment.