Skip to content

Commit

Permalink
Merge pull request #1246 from kom-senapati/llm/groq
Browse files Browse the repository at this point in the history
Groq llms added
  • Loading branch information
dartpain authored Oct 7, 2024
2 parents 4632531 + dc0f26d commit cbae7bd
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions application/api/answer/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
gpt_model = "gpt-3.5-turbo"
elif settings.LLM_NAME == "anthropic":
gpt_model = "claude-2"
elif settings.LLM_NAME == "groq":
gpt_model = "llama3-8b-8192"

if settings.MODEL_NAME: # in case there is particular model name configured
gpt_model = settings.MODEL_NAME
Expand Down
45 changes: 45 additions & 0 deletions application/llm/groq.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from application.llm.base import BaseLLM



class GroqLLM(BaseLLM):

def __init__(self, api_key=None, user_api_key=None, *args, **kwargs):
from openai import OpenAI

super().__init__(*args, **kwargs)
self.client = OpenAI(api_key=api_key, base_url="https://api.groq.com/openai/v1")
self.api_key = api_key
self.user_api_key = user_api_key

def _raw_gen(
self,
baseself,
model,
messages,
stream=False,
**kwargs
):
response = self.client.chat.completions.create(
model=model, messages=messages, stream=stream, **kwargs
)

return response.choices[0].message.content

def _raw_gen_stream(
self,
baseself,
model,
messages,
stream=True,
**kwargs
):
response = self.client.chat.completions.create(
model=model, messages=messages, stream=stream, **kwargs
)

for line in response:
# import sys
# print(line.choices[0].delta.content, file=sys.stderr)
if line.choices[0].delta.content is not None:
yield line.choices[0].delta.content
2 changes: 2 additions & 0 deletions application/llm/llm_creator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from application.llm.groq import GroqLLM
from application.llm.openai import OpenAILLM, AzureOpenAILLM
from application.llm.sagemaker import SagemakerAPILLM
from application.llm.huggingface import HuggingFaceLLM
Expand All @@ -17,6 +18,7 @@ class LLMCreator:
"anthropic": AnthropicLLM,
"docsgpt": DocsGPTAPILLM,
"premai": PremAILLM,
"groq": GroqLLM
}

@classmethod
Expand Down

0 comments on commit cbae7bd

Please sign in to comment.