Skip to content

Commit

Permalink
fixed the bug with function calling
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkulaga committed Oct 17, 2024
1 parent c03c632 commit d8c45bf
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
python-version: ["3.10", "3.11"]
python-version: ["3.11"]

env:
GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }}
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,8 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/

.DS_Store

# VSCode
.vscode/
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
2 changes: 1 addition & 1 deletion environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies:
- typer>=0.12.5 #for CLI
- twine #for publishing
- pip:
- litellm>=1.48.11
- litellm>=1.49.5
- numpydoc
- semanticscholar>=0.8.4
- Mako>=1.3.5 #optional, might be deleted in the future
17 changes: 0 additions & 17 deletions environment_qwen2.yaml

This file was deleted.

19 changes: 14 additions & 5 deletions examples/function_calling.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,28 @@ async def process_stream(async_generator):
# You can also process each item here if needed
return collected_data

llm_options = just_agents.llm_options.OPENAI_GPT4oMINI
#llm_options = just_agents.llm_options.OPENAI_GPT4oMINI
llm_options = just_agents.llm_options.LLAMA3_2

key_getter = rotate_env_keys
prompt = "What's the weather like in San Francisco, Tokyo, and Paris?"


load_dotenv(override=True)
session: LLMSession = LLMSession(
llm_options=llm_options,
llm_options=just_agents.llm_options.OPENAI_GPT4oMINI,
tools=[get_current_weather]
)
result = session.query("What's the weather like in San Francisco, Tokyo, and Paris?")


session.memory.add_on_message(lambda m: pprint.pprint(m) if "content" in m is not None else None)
session.query(prompt)
result = session.query(prompt)

"""
print("And now same query but async mode for streaming. Note: we use asyncio.run here to run the stream")
stream = session.stream(prompt)
result = asyncio.run(process_stream(stream))
print("stream finished")
print("stream finished")
"""
print("RESULT+++++++++++++++++++++++++++++++++++++++++++++++")
print(result)
14 changes: 8 additions & 6 deletions just_agents/llm_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,19 @@


class LLMSession(IAgent):
available_tools: dict[str, Callable] = dict()
memory: Memory = Memory()
streaming: AbstractStreaming = None
key_getter: RotateKeys = None
on_response: list[OnCompletion] = []



def __init__(self, llm_options: dict[str, Any] = None,
system_prompt:str = None,
agent_schema: str | Path | dict | None = None,
tools: list[Callable] = None):
tools: Optional[list[Callable]] = None):
self.on_response = []
self.available_tools: Optional[dict[str, Callable]] = {}
self.memory: Memory = Memory()
self.streaming: AbstractStreaming = None
self.key_getter: RotateKeys = None
self.on_response: list[OnCompletion] = []

self.agent_schema = resolve_agent_schema(agent_schema, "LLMSession", "llm_session_schema.yaml")
self.llm_options: dict[str, Any] = resolve_llm_options(self.agent_schema, llm_options)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
with codecs.open(os.path.join(here, "README.md"), encoding="utf-8") as fh:
long_description = "\n" + fh.read()

VERSION = '0.1.1'
VERSION = '0.2.0'
DESCRIPTION = 'Just Agents'
LONG_DESCRIPTION = 'LLM Agents that are implemented without unnecessary complexity'

Expand Down
Empty file added tests/execute.py
Empty file.
3 changes: 3 additions & 0 deletions tests/test_cot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
from dotenv import load_dotenv
from just_agents.cot_agent import ChainOfThoughtAgent
import pytest

import just_agents.llm_options

Expand All @@ -13,6 +14,7 @@ def count_letters(character:str, word:str) -> str:
print("Function: ", character, " occurres in ", word, " ", count, " times.")
return str(count)


def test_function_query():
load_dotenv(override = True)

Expand All @@ -27,6 +29,7 @@ async def process_stream(async_generator):
for item in async_generator:
print(item)


def test_stream_function_query():
load_dotenv(override = True)

Expand Down
10 changes: 5 additions & 5 deletions tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import just_agents.llm_options
from just_agents.llm_session import LLMSession
import asyncio
from mock import *
from tests.mock import *


def get_current_weather(location: str):
Expand All @@ -25,7 +25,7 @@ def get_current_weather(location: str):
def test_sync_function_calling():
load_dotenv(override=True)
session: LLMSession = LLMSession(
llm_options=just_agents.llm_options.OPENAI_GPT4oMINI,
llm_options=just_agents.llm_options.LLAMA3_2,
tools=[get_current_weather]
)
result = session.query("What's the weather like in San Francisco, Tokyo, and Paris?")
Expand All @@ -40,7 +40,7 @@ async def process_stream(async_generator):
def test_stream_function_calling():
load_dotenv(override=True)
session: LLMSession = LLMSession(
llm_options=just_agents.llm_options.OPENAI_GPT4oMINI,
llm_options=just_agents.llm_options.LLAMA3_2,
tools=[get_current_weather]
)
stream = session.stream("What's the weather like in San Francisco, Tokyo, and Paris?")
Expand All @@ -53,9 +53,9 @@ def test_stream_function_calling():


def test_stream_genetics_function_calling():
load_dotenv()
load_dotenv(override=True)
session: LLMSession = LLMSession(
llm_options=just_agents.llm_options.OPENAI_GPT4oMINI,
llm_options=just_agents.llm_options.LLAMA3_2,
tools=[hybrid_search, rsid_lookup, gene_lookup, pathway_lookup, disease_lookup, sequencing_info, clinical_trails_full_trial]
)
stream = session.stream("What is the influence of different alleles in rs10937739?")
Expand Down

0 comments on commit d8c45bf

Please sign in to comment.