Skip to content

Commit

Permalink
Merge pull request #1441 from arc53/google-llm
Browse files Browse the repository at this point in the history
  • Loading branch information
dartpain authored Nov 15, 2024
2 parents 2245f46 + 144ab61 commit 4443bc7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
48 changes: 48 additions & 0 deletions application/llm/google_ai.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from application.llm.base import BaseLLM

class GoogleLLM(BaseLLM):

def __init__(self, api_key=None, user_api_key=None, *args, **kwargs):

super().__init__(*args, **kwargs)
self.api_key = api_key
self.user_api_key = user_api_key

def _clean_messages_google(self, messages):
return [
{
"role": "model" if message["role"] == "system" else message["role"],
"parts": [message["content"]],
}
for message in messages[1:]
]

def _raw_gen(
self,
baseself,
model,
messages,
stream=False,
**kwargs
):
import google.generativeai as genai
genai.configure(api_key=self.api_key)
model = genai.GenerativeModel(model, system_instruction=messages[0]["content"])
response = model.generate_content(self._clean_messages_google(messages))
return response.text

def _raw_gen_stream(
self,
baseself,
model,
messages,
stream=True,
**kwargs
):
import google.generativeai as genai
genai.configure(api_key=self.api_key)
model = genai.GenerativeModel(model, system_instruction=messages[0]["content"])
response = model.generate_content(self._clean_messages_google(messages), stream=True)
for line in response:
if line.text is not None:
yield line.text
4 changes: 3 additions & 1 deletion application/llm/llm_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from application.llm.anthropic import AnthropicLLM
from application.llm.docsgpt_provider import DocsGPTAPILLM
from application.llm.premai import PremAILLM
from application.llm.google_ai import GoogleLLM


class LLMCreator:
Expand All @@ -18,7 +19,8 @@ class LLMCreator:
"anthropic": AnthropicLLM,
"docsgpt": DocsGPTAPILLM,
"premai": PremAILLM,
"groq": GroqLLM
"groq": GroqLLM,
"google": GoogleLLM
}

@classmethod
Expand Down

0 comments on commit 4443bc7

Please sign in to comment.