Skip to content

Commit

Permalink
+ models list api for alt llm providers
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnyjohnson1 committed Aug 13, 2024
1 parent 3175f06 commit 7b8ba46
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
36 changes: 25 additions & 11 deletions topos/api/api_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,23 +268,37 @@ async def create_next_messages(request: ConversationTopicsRequest):


@router.post("/list_models")
async def list_models():
# model specifications
# TODO UPDATE SO ITS NOT HARDCODED
# TODO UPDATE THIS ONE!!!!
# model = request.model if request.model != None else "dolphin-llama3"
# provider = 'ollama' # defaults to ollama right now
# api_key = 'ollama'
async def list_models(provider: str = 'ollama', api_key: str = 'ollama'):
# Define the URLs for different providers

list_models_urls = {
'ollama': "http://localhost:11434/api/tags",
'openai': "https://api.openai.com/v1/models",
'groq': "https://api.groq.com/openai/v1/models"
}

if provider not in list_models_urls:
raise HTTPException(status_code=400, detail="Unsupported provider")

# Get the appropriate URL based on the provider
url = list_models_urls.get(provider.lower())

# llm_client = LLMChatGens(model_name=model, provider=provider, api_key=api_key)
if provider.lower() == 'ollama':
# No need for headers with Ollama
headers = {}
else:
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}

url = "http://localhost:11434/api/tags"
try:
result = requests.get(url)
# Make the request with the appropriate headers
result = requests.get(url, headers=headers)
if result.status_code == 200:
return {"result": result.json()}
else:
raise HTTPException(status_code=404, detail="Models not found")
raise HTTPException(status_code=result.status_code, detail="Models not found")
except requests.ConnectionError:
raise HTTPException(status_code=500, detail="Server connection error")

Expand Down
6 changes: 0 additions & 6 deletions topos/generations/groq_chat.py

This file was deleted.

0 comments on commit 7b8ba46

Please sign in to comment.