Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting proxy #458

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions apps/browser/sitefind.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
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.
If you don't know a website use https://www.google.com/search?q=query and
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)
diegoarceof marked this conversation as resolved.
Show resolved Hide resolved
return completion.choices[0].message.content
7 changes: 6 additions & 1 deletion apps/browser/siteuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand All @@ -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:
Expand Down
9 changes: 7 additions & 2 deletions apps/hal9/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
diegoarceof marked this conversation as resolved.
Show resolved Hide resolved
model = MODEL,
messages = messages,
temperature = 0,
Expand Down
6 changes: 3 additions & 3 deletions apps/hal9/tools/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 12 additions & 2 deletions apps/hal9/tools/hal9.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from groq import Groq
from openai import OpenAI
import os
import hal9 as h9
import json
Expand All @@ -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(
diegoarceof marked this conversation as resolved.
Show resolved Hide resolved
model = "llama3-70b-8192",
messages = messages,
temperature = 0,
seed = 1,
stream = True)

response = ""
for chunk in stream:
Expand Down
6 changes: 3 additions & 3 deletions apps/hal9/tools/image_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
diegoarceof marked this conversation as resolved.
Show resolved Hide resolved
api_key = 'h1',
api_version = '2023-05-15'
)

response = client.chat.completions.create(
Expand Down
6 changes: 3 additions & 3 deletions apps/hal9/tools/streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand Down
6 changes: 3 additions & 3 deletions apps/hal9/tools/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 12 additions & 5 deletions apps/swarm/app.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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,
Expand All @@ -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
)
Expand Down