-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from Deeptechia/main
Geppetto v0.2.0
- Loading branch information
Showing
22 changed files
with
867 additions
and
138 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# To get started with Dependabot version updates, you'll need to specify which | ||
# package ecosystems to update and where the package manifests are located. | ||
# Please see the documentation for all configuration options: | ||
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file | ||
|
||
version: 2 | ||
updates: | ||
- package-ecosystem: "cargo" # See documentation for possible values | ||
directory: "/" # Location of package manifests | ||
schedule: | ||
interval: "weekly" |
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,15 +1,16 @@ | ||
name: GitlabSync | ||
|
||
on: | ||
- push | ||
- delete | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
sync: | ||
runs-on: ubuntu-latest | ||
name: Git Repo Sync | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- uses: wangchucheng/[email protected] | ||
|
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
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,6 +1,8 @@ | ||
SLACK_BOT_TOKEN = "YOUR_TOKEN" | ||
SLACK_APP_TOKEN = "YOUR_TOKEN" | ||
OPENAI_API_KEY = "YOUR_TOKEN" | ||
CHATGPT_MODEL = "gpt-4" | ||
CHATGPT_MODEL = "gpt-4-turbo" | ||
DALLE_MODEL = "dall-e-3" | ||
SIGNING_SECRET = "YOUR_SECRET" | ||
GOOGLE_API_KEY = "YOUR_TOKEN" | ||
GEMINI_MODEL = "gemini-pro" |
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,4 +1,5 @@ | ||
{ | ||
"*":"*", | ||
"User A": "#MemberIDUserA", | ||
"User B": "#MemberIDUSerB" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Geppetto Exceptions | ||
|
||
|
||
class InvalidThreadFormatError(KeyError): | ||
"""Invalid thread format. | ||
Raise if the submitted thread format doesn't have the expected layout. | ||
Since the UIs and the underlying LLM engines must meet an interface, | ||
some validations have to be undertaken to assure key fields. | ||
""" |
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,61 @@ | ||
from urllib.request import urlopen | ||
import logging | ||
|
||
from .exceptions import InvalidThreadFormatError | ||
from .llm_api_handler import LLMHandler | ||
from dotenv import load_dotenv | ||
from typing import List, Dict | ||
import os | ||
import textwrap | ||
import google.generativeai as genai | ||
from IPython.display import display | ||
from IPython.display import Markdown | ||
|
||
load_dotenv(os.path.join("config", ".env")) | ||
|
||
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY") | ||
GEMINI_MODEL=os.getenv("GEMINI_MODEL", "gemini-pro") | ||
MSG_FIELD = "parts" | ||
MSG_INPUT_FIELD = "content" | ||
|
||
def to_markdown(text): | ||
text = text.replace('•', ' *') | ||
return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True)) | ||
|
||
class GeminiHandler(LLMHandler): | ||
|
||
def __init__( | ||
self, | ||
personality, | ||
): | ||
super().__init__( | ||
'Gemini', | ||
GEMINI_MODEL, | ||
genai.GenerativeModel(GEMINI_MODEL), | ||
) | ||
self.personality = personality | ||
self.system_role = "system" | ||
self.assistant_role = "model" | ||
self.user_role = "user" | ||
genai.configure(api_key=GOOGLE_API_KEY) | ||
|
||
def llm_generate_content(self, user_prompt, status_callback=None, *status_callback_args): | ||
logging.info("Sending msg to gemini: %s" % user_prompt) | ||
if len(user_prompt) >= 2 and user_prompt[0].get('role') == 'user' and user_prompt[1].get('role') == 'user': | ||
merged_prompt = { | ||
'role': 'user', | ||
'parts': [msg['parts'][0] for msg in user_prompt[:2]] | ||
} | ||
user_prompt = [merged_prompt] + user_prompt[2:] | ||
response= self.client.generate_content(user_prompt) | ||
markdown_response = to_markdown(response.text) | ||
return str(markdown_response.data) | ||
|
||
def get_prompt_from_thread(self, thread: List[Dict], assistant_tag: str, user_tag: str): | ||
prompt = super().get_prompt_from_thread(thread, assistant_tag, user_tag) | ||
for msg in prompt: | ||
if MSG_INPUT_FIELD in msg: | ||
msg[MSG_FIELD] = [msg.pop(MSG_INPUT_FIELD)] | ||
else: | ||
raise InvalidThreadFormatError("The input thread doesn't have the field %s" % MSG_INPUT_FIELD) | ||
return prompt |
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,30 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import List, Dict, Callable | ||
from .exceptions import InvalidThreadFormatError | ||
|
||
ROLE_FIELD = "role" | ||
|
||
class LLMHandler(ABC): | ||
def __init__(self, name, model, client): | ||
self.name = name | ||
self.model = model | ||
self.client = client | ||
|
||
def get_info(self): | ||
return f"Name: {self.name} - Model: {self.model}" | ||
|
||
@abstractmethod | ||
def llm_generate_content(self, prompt: str, callback: Callable, *callback_args): | ||
pass | ||
|
||
def get_prompt_from_thread(self, thread: List[Dict], assistant_tag: str, user_tag: str): | ||
prompt = [] | ||
for msg in thread: | ||
formatted_msg = dict(msg) | ||
if ROLE_FIELD in formatted_msg: | ||
formatted_msg[ROLE_FIELD] = formatted_msg[ROLE_FIELD].replace(assistant_tag, self.assistant_role) | ||
formatted_msg[ROLE_FIELD] = formatted_msg[ROLE_FIELD].replace(user_tag, self.user_role) | ||
prompt.append(formatted_msg) | ||
else: | ||
raise InvalidThreadFormatError("The input thread doesn't have the field %s" % ROLE_FIELD) | ||
return prompt |
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,36 @@ | ||
from typing import List, Type, TypedDict, Dict | ||
from .llm_api_handler import LLMHandler | ||
|
||
|
||
class LLMCfgRec(TypedDict): | ||
name: str | ||
handler: Type[LLMHandler] | ||
handler_args: Dict | ||
|
||
|
||
LLMCfgs = List[LLMCfgRec] | ||
|
||
|
||
class LLMController: | ||
|
||
def __init__(self, llm_cfgs: LLMCfgs): | ||
self.llm_cfgs = llm_cfgs | ||
self.handlers = {} | ||
|
||
def init_controller(self): | ||
for llm in self.llm_cfgs: | ||
name = llm['name'] | ||
self.handlers[name] = self.get_handler(name) | ||
|
||
def list_llms(self): | ||
return [x['name'] for x in self.llm_cfgs] | ||
|
||
def get_llm_cfg(self, name): | ||
for llm in self.llm_cfgs: | ||
if llm['name'] == name: | ||
return llm | ||
raise ValueError("LLM configuration not found for name: %s" % name) | ||
|
||
def get_handler(self, name): | ||
llm_cfg = self.get_llm_cfg(name) | ||
return llm_cfg['handler'](**llm_cfg['handler_args']) |
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
Oops, something went wrong.