Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] feat: adding llm_endpoint for openai-compatible backends #7

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,13 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Visual Studio code local settings
.vscode/

# SSH Keys
*_host_key
*.key
*.pub

# config files
*.ini
*.ini
2 changes: 2 additions & 0 deletions SSH/config.ini.TEMPLATE
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ server_version_string = OpenSSH_8.2p1 Ubuntu-4ubuntu0.3
##### OpenAI
llm_provider = openai
model_name = gpt-4o
# if you want to specify another OpenAI-compatible endpoint
# llm_endpoint = https://example.com

##### ollama llama3
#llm_provider = ollama
Expand Down
28 changes: 19 additions & 9 deletions SSH/ssh_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
from base64 import b64encode
from operator import itemgetter
from langchain_openai import ChatOpenAI
from langchain_aws import ChatBedrock, ChatBedrockConverse
from langchain_aws import ChatBedrockConverse
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_ollama import ChatOllama
from langchain_core.messages import HumanMessage, SystemMessage, trim_messages
from langchain_core.messages import HumanMessage, trim_messages
from langchain_core.chat_history import BaseChatMessageHistory, InMemoryChatMessageHistory
from langchain_core.runnables.history import RunnableWithMessageHistory
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
Expand Down Expand Up @@ -295,7 +295,7 @@ def llm_get_session_history(session_id: str) -> BaseChatMessageHistory:
return llm_sessions[session_id]

def get_user_accounts() -> dict:
if (not 'user_accounts' in config) or (len(config.items('user_accounts')) == 0):
if ("user_accounts" not in config) or (len(config.items("user_accounts")) == 0):
raise ValueError("No user accounts found in configuration file.")

accounts = dict()
Expand All @@ -305,15 +305,21 @@ def get_user_accounts() -> dict:

return accounts

def choose_llm(llm_provider: Optional[str] = None, model_name: Optional[str] = None):
llm_provider_name = llm_provider or config['llm'].get("llm_provider", "openai")
def choose_llm(
llm_provider: Optional[str] = None,
model_name: Optional[str] = None,
llm_endpoint: Optional[str] = None,
):
llm_provider_name: str
if llm_provider is not None:
llm_provider_name = llm_provider
else:
llm_provider_name = config["llm"].get("llm_provider", "openai")
llm_provider_name = llm_provider_name.lower()
model_name = model_name or config['llm'].get("model_name", "gpt-3.5-turbo")

if llm_provider_name == 'openai':
llm_model = ChatOpenAI(
model=model_name
)
llm_model = ChatOpenAI(model=model_name, endpoint=llm_endpoint)
elif llm_provider_name == 'ollama':
llm_model = ChatOllama(
model=model_name
Expand Down Expand Up @@ -452,7 +458,11 @@ def get_prompts(prompt: Optional[str], prompt_file: Optional[str]) -> dict:
llm_system_prompt = prompts["system_prompt"]
llm_user_prompt = prompts["user_prompt"]

llm = choose_llm(config['llm'].get("llm_provider"), config['llm'].get("model_name"))
llm = choose_llm(
config["llm"].get("llm_provider"),
config["llm"].get("model_name"),
config["llm"].get("llm_endpoint"),
)

llm_sessions = dict()

Expand Down