From 082b792af5e4de652315992f2d7cd907e7c65e7d Mon Sep 17 00:00:00 2001 From: Diego Arceo Date: Tue, 10 Dec 2024 08:21:47 -0600 Subject: [PATCH 1/4] Adding proxy to hal9 apps agents --- apps/hal9/app.py | 9 +++++++-- apps/hal9/tools/game.py | 6 +++--- apps/hal9/tools/hal9.py | 14 ++++++++++++-- apps/hal9/tools/image_analyzer.py | 6 +++--- apps/hal9/tools/streamlit.py | 6 +++--- apps/hal9/tools/website.py | 6 +++--- 6 files changed, 31 insertions(+), 16 deletions(-) diff --git a/apps/hal9/app.py b/apps/hal9/app.py index 7c687510..0f01f0fc 100644 --- a/apps/hal9/app.py +++ b/apps/hal9/app.py @@ -2,7 +2,7 @@ import os import hal9 as h9 import json -import openai +from openai import OpenAI from tools.calculator import calculate from tools.game import build_game @@ -17,7 +17,12 @@ MODEL = "llama3-groq-70b-8192-tool-use-preview" def run(messages, tools): - return Groq().chat.completions.create( + client = OpenAI( + base_url="http://localhost:5000/proxy/server=https://api.groq.com/openai/v1", + api_key = "h9" + ) + + return client.chat.completions.create( model = MODEL, messages = messages, temperature = 0, diff --git a/apps/hal9/tools/game.py b/apps/hal9/tools/game.py index 89d04ca6..a6bfbe12 100644 --- a/apps/hal9/tools/game.py +++ b/apps/hal9/tools/game.py @@ -5,9 +5,9 @@ import time client = openai.AzureOpenAI( - azure_endpoint='https://openai-hal9.openai.azure.com/', - api_key=os.environ['OPENAI_AZURE'], - api_version='2023-05-15', + azure_endpoint = 'http://localhost:5000/proxy/server=https://openai-hal9.openai.azure.com/', + api_key = 'h1', + api_version = '2023-05-15' ) def build_game(user_game_request): diff --git a/apps/hal9/tools/hal9.py b/apps/hal9/tools/hal9.py index 2143c25d..be4b6589 100644 --- a/apps/hal9/tools/hal9.py +++ b/apps/hal9/tools/hal9.py @@ -1,4 +1,4 @@ -from groq import Groq +from openai import OpenAI import os import hal9 as h9 import json @@ -15,7 +15,17 @@ def hal9_reply(prompt): {"role": "user", "content": prompt} ] - stream = Groq().chat.completions.create(model = "llama3-70b-8192", messages = messages, temperature = 0, seed = 1, stream = True) + client = OpenAI( + base_url="http://localhost:5000/proxy/server=https://api.groq.com/openai/v1", + api_key = "h9" + ) + + stream = client.chat.completions.create( + model = "llama3-70b-8192", + messages = messages, + temperature = 0, + seed = 1, + stream = True) response = "" for chunk in stream: diff --git a/apps/hal9/tools/image_analyzer.py b/apps/hal9/tools/image_analyzer.py index 79d3042e..80a20835 100644 --- a/apps/hal9/tools/image_analyzer.py +++ b/apps/hal9/tools/image_analyzer.py @@ -8,9 +8,9 @@ def image_analyzer(image_url, prompt): 'prompt' = description of what the user wants to analyze in the image. If the user does not specify, it should default to "What's in this image?" """ client = openai.AzureOpenAI( - azure_endpoint = 'https://openai-hal9.openai.azure.com/', - api_key = os.environ['OPENAI_AZURE'], - api_version = '2024-02-15-preview', + azure_endpoint = 'http://localhost:5000/proxy/server=https://openai-hal9.openai.azure.com/', + api_key = 'h1', + api_version = '2023-05-15' ) response = client.chat.completions.create( diff --git a/apps/hal9/tools/streamlit.py b/apps/hal9/tools/streamlit.py index 4ed2e9bc..20f4db0b 100644 --- a/apps/hal9/tools/streamlit.py +++ b/apps/hal9/tools/streamlit.py @@ -9,9 +9,9 @@ def build_streamlit(prompt): 'prompt' = with user change or requirements """ client = openai.AzureOpenAI( - azure_endpoint = 'https://openai-hal9.openai.azure.com/', - api_key = os.environ['OPENAI_AZURE'], - api_version = '2023-05-15', + azure_endpoint = 'http://localhost:5000/proxy/server=https://openai-hal9.openai.azure.com/', + api_key = 'h1', + api_version = '2023-05-15' ) system = """ diff --git a/apps/hal9/tools/website.py b/apps/hal9/tools/website.py index b897de7f..e5375599 100644 --- a/apps/hal9/tools/website.py +++ b/apps/hal9/tools/website.py @@ -9,9 +9,9 @@ def build_website(prompt): 'prompt' with user change or requirements """ client = openai.AzureOpenAI( - azure_endpoint = 'https://openai-hal9.openai.azure.com/', - api_key = os.environ['OPENAI_AZURE'], - api_version = '2023-05-15', + azure_endpoint = 'http://localhost:5000/proxy/server=https://openai-hal9.openai.azure.com/', + api_key = 'h1', + api_version = '2023-05-15' ) system = """You can build html applications for user requests. Your replies can include markdown code blocks but they must include a filename parameter after the language. For example, From 763e615c951e5f2af6436679a549b5759e3adfc8 Mon Sep 17 00:00:00 2001 From: Diego Arceo Date: Tue, 10 Dec 2024 08:22:25 -0600 Subject: [PATCH 2/4] Adding proxy to browser app agents --- apps/browser/sitefind.py | 10 +++++++--- apps/browser/siteuse.py | 7 ++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/apps/browser/sitefind.py b/apps/browser/sitefind.py index 19ae72f7..f8c2a58b 100644 --- a/apps/browser/sitefind.py +++ b/apps/browser/sitefind.py @@ -1,5 +1,4 @@ -import hal9 as h9 -from groq import Groq +from openai import OpenAI system_prompt = """ Only reply with website urls that best match the task from the user prompt. @@ -7,7 +6,12 @@ replace query with a reasonable search query for the user task """ +client = OpenAI( + base_url="http://localhost:5000/proxy/server=https://api.groq.com/openai/v1", + api_key = "h9" +) + def site_find(prompt): messages = [{ "role": "system", "content": system_prompt}, { "role": "user", "content": prompt }] - completion = Groq().chat.completions.create(model = "llama3-70b-8192", messages = messages) + completion = client.chat.completions.create(model = "llama3-70b-8192", messages = messages) return completion.choices[0].message.content diff --git a/apps/browser/siteuse.py b/apps/browser/siteuse.py index 68975113..4df8c28c 100644 --- a/apps/browser/siteuse.py +++ b/apps/browser/siteuse.py @@ -32,6 +32,11 @@ Only reply with a code block for python code. """ +client = OpenAI( + base_url="https://api.hal9.com/proxy/server=https://api.openai.com/v1/", + api_key = "h9" +) + def site_use(prompt, current, elements): elements_str = "\n".join([f"{item['text']}: {item['query']}" for item in elements]) @@ -47,7 +52,7 @@ def site_use(prompt, current, elements): """ } ] - completion = OpenAI().chat.completions.create(model = "gpt-4", messages = messages) + completion = client.chat.completions.create(model = "gpt-4", messages = messages) content = completion.choices[0].message.content extracted = h9.extract(content, language = "*") if not extracted or len(extracted) == 0: From d5c8f259bce8e0c7e8c6b01c5cd9efeaebbab4f9 Mon Sep 17 00:00:00 2001 From: Diego Arceo Date: Tue, 10 Dec 2024 08:22:45 -0600 Subject: [PATCH 3/4] Adding proxy to swarm --- apps/swarm/app.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/apps/swarm/app.py b/apps/swarm/app.py index c2247028..289e7692 100644 --- a/apps/swarm/app.py +++ b/apps/swarm/app.py @@ -1,7 +1,9 @@ -import json -import hal9 as h9 from dotenv import load_dotenv -from swarm import Swarm, Agent, repl +import hal9 as h9 +import json +from openai import OpenAI +from swarm import Swarm, Agent + from recomendations import book_recommendation, comic_recommendation, movie_recommendation load_dotenv() @@ -42,7 +44,12 @@ def transfer_to_movie_expert(): functions=[transfer_to_book_expert, transfer_to_comic_expert, transfer_to_movie_expert], ) -client = Swarm() +client = OpenAI( + base_url="http://localhost:5000/proxy/server=https://api.anthropic.com/v1/messages", + api_key = "h9" +) +swarm = Swarm(client = client) + messages = h9.load('messages', []) agents = {'Receptionist': receptionist, @@ -53,7 +60,7 @@ def transfer_to_movie_expert(): user_input = input() messages.append({"role": "user", "content": user_input}) -response = client.run( +response = swarm.run( agent=agent, messages=messages ) From 28ef92a7061982b6b54b18d0ee255c9b4434b945 Mon Sep 17 00:00:00 2001 From: Diego Arceo Date: Tue, 10 Dec 2024 18:18:29 -0600 Subject: [PATCH 4/4] Fixed proxy urls --- apps/browser/sitefind.py | 6 +++--- apps/hal9/app.py | 6 +++--- apps/hal9/tools/hal9.py | 8 ++++---- apps/hal9/tools/image_analyzer.py | 2 +- apps/hal9/tools/streamlit.py | 2 +- apps/hal9/tools/website.py | 2 +- apps/swarm/app.py | 6 +++--- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/apps/browser/sitefind.py b/apps/browser/sitefind.py index f8c2a58b..da544118 100644 --- a/apps/browser/sitefind.py +++ b/apps/browser/sitefind.py @@ -1,4 +1,4 @@ -from openai import OpenAI +from groq import Groq system_prompt = """ Only reply with website urls that best match the task from the user prompt. @@ -6,8 +6,8 @@ replace query with a reasonable search query for the user task """ -client = OpenAI( - base_url="http://localhost:5000/proxy/server=https://api.groq.com/openai/v1", +client = Groq( + base_url= "https://api.hal9.com/proxy/server=https://api.groq.com/", api_key = "h9" ) diff --git a/apps/hal9/app.py b/apps/hal9/app.py index 0f01f0fc..0365e306 100644 --- a/apps/hal9/app.py +++ b/apps/hal9/app.py @@ -17,10 +17,10 @@ MODEL = "llama3-groq-70b-8192-tool-use-preview" def run(messages, tools): - client = OpenAI( - base_url="http://localhost:5000/proxy/server=https://api.groq.com/openai/v1", + client = Groq( + base_url= "https://api.hal9.com/proxy/server=https://api.groq.com/", api_key = "h9" - ) +) return client.chat.completions.create( model = MODEL, diff --git a/apps/hal9/tools/hal9.py b/apps/hal9/tools/hal9.py index be4b6589..42034a82 100644 --- a/apps/hal9/tools/hal9.py +++ b/apps/hal9/tools/hal9.py @@ -1,4 +1,4 @@ -from openai import OpenAI +from groq import Groq import os import hal9 as h9 import json @@ -15,10 +15,10 @@ def hal9_reply(prompt): {"role": "user", "content": prompt} ] - client = OpenAI( - base_url="http://localhost:5000/proxy/server=https://api.groq.com/openai/v1", + client = Groq( + base_url= "https://api.hal9.com/proxy/server=https://api.groq.com/", api_key = "h9" - ) + ) stream = client.chat.completions.create( model = "llama3-70b-8192", diff --git a/apps/hal9/tools/image_analyzer.py b/apps/hal9/tools/image_analyzer.py index 80a20835..1b92c417 100644 --- a/apps/hal9/tools/image_analyzer.py +++ b/apps/hal9/tools/image_analyzer.py @@ -8,7 +8,7 @@ def image_analyzer(image_url, prompt): 'prompt' = description of what the user wants to analyze in the image. If the user does not specify, it should default to "What's in this image?" """ client = openai.AzureOpenAI( - azure_endpoint = 'http://localhost:5000/proxy/server=https://openai-hal9.openai.azure.com/', + azure_endpoint = 'https://api.hal9.com/proxy/server=https://openai-hal9.openai.azure.com/', api_key = 'h1', api_version = '2023-05-15' ) diff --git a/apps/hal9/tools/streamlit.py b/apps/hal9/tools/streamlit.py index 20f4db0b..c501be4c 100644 --- a/apps/hal9/tools/streamlit.py +++ b/apps/hal9/tools/streamlit.py @@ -9,7 +9,7 @@ def build_streamlit(prompt): 'prompt' = with user change or requirements """ client = openai.AzureOpenAI( - azure_endpoint = 'http://localhost:5000/proxy/server=https://openai-hal9.openai.azure.com/', + azure_endpoint = 'https://api.hal9.com/proxy/server=https://openai-hal9.openai.azure.com/', api_key = 'h1', api_version = '2023-05-15' ) diff --git a/apps/hal9/tools/website.py b/apps/hal9/tools/website.py index e5375599..10acfc8f 100644 --- a/apps/hal9/tools/website.py +++ b/apps/hal9/tools/website.py @@ -9,7 +9,7 @@ def build_website(prompt): 'prompt' with user change or requirements """ client = openai.AzureOpenAI( - azure_endpoint = 'http://localhost:5000/proxy/server=https://openai-hal9.openai.azure.com/', + azure_endpoint = 'https://api.hal9.com/proxy/server=https://openai-hal9.openai.azure.com/', api_key = 'h1', api_version = '2023-05-15' ) diff --git a/apps/swarm/app.py b/apps/swarm/app.py index 289e7692..e4dfb3b3 100644 --- a/apps/swarm/app.py +++ b/apps/swarm/app.py @@ -45,9 +45,9 @@ def transfer_to_movie_expert(): ) client = OpenAI( - base_url="http://localhost:5000/proxy/server=https://api.anthropic.com/v1/messages", - api_key = "h9" -) + base_url="https://api.hal9.com/proxy/server=https://api.openai.com/v1/", + api_key = "h9" +) swarm = Swarm(client = client) messages = h9.load('messages', [])