-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it work with both openai and ollama
- Loading branch information
1 parent
d974875
commit 24b9980
Showing
5 changed files
with
84 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ data/* | |
.DS_STORE | ||
*.db | ||
*.csv | ||
*__pycache__ | ||
*__pycache__ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
from dotenv import load_dotenv | ||
load_dotenv() | ||
import os | ||
|
||
TABLE_NAME = "tb" | ||
DATABASE_NAME = "db.db" | ||
DATABASE_NAME = "db.db" | ||
|
||
OPENAI_API_KEY=os.getenv('OPENAI_API_KEY') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import requests | ||
import json | ||
from openai import OpenAI | ||
from src.constants import OPENAI_API_KEY | ||
|
||
print(OPENAI_API_KEY) | ||
client = OpenAI() | ||
client.api_key = OPENAI_API_KEY | ||
|
||
def execute_with_ollama(query): | ||
payload = { | ||
"model": "mistral", | ||
"format": "json", | ||
"stream": False, | ||
"messages": [ | ||
{"role": "user", "content": query} | ||
] | ||
} | ||
|
||
payload_json = json.dumps(payload) | ||
url = 'http://localhost:11434/api/chat' | ||
|
||
try: | ||
response = requests.post(url, data=payload_json) | ||
|
||
if response.status_code == 200: | ||
response_data = response.json() | ||
response_data = json.loads(response_data['message']['content']) | ||
print(response_data) | ||
return response_data | ||
else: | ||
print(f"LLM Request failed with status code {response.status_code}") | ||
return None | ||
except requests.RequestException as e: | ||
print(f"Request exception: {e}") | ||
return None | ||
|
||
|
||
def execute_with_openai(query): | ||
completion = client.chat.completions.create( | ||
model="gpt-3.5-turbo-1106", | ||
messages=[ | ||
{ | ||
"role": "system", | ||
"content":query | ||
}, | ||
], | ||
temperature=0.7, | ||
max_tokens=64, | ||
top_p=1, | ||
response_format={ "type": "json_object" }, | ||
) | ||
response = completion.choices[0].message.content; | ||
print(response) | ||
response = json.loads(response) | ||
return response | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters