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

Add ChatGPT fine-tuned model option #234

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ AZURE_OPENAI_API_VERSION=placeholder
CONNERY_RUNNER_URL=https://your-personal-connery-runner-url
CONNERY_RUNNER_API_KEY=placeholder
PROXY_URL=your_proxy_url

# (optional) Custom/fine-tune chatGPT model name
FINE_TUNED_GPT_MODEL=placeholder
12 changes: 11 additions & 1 deletion backend/app/agent.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

import os
from enum import Enum
from typing import Any, Mapping, Optional, Sequence, Union

Expand Down Expand Up @@ -63,7 +65,7 @@ class AgentType(str, Enum):
CLAUDE2 = "Claude 2"
BEDROCK_CLAUDE2 = "Claude 2 (Amazon Bedrock)"
GEMINI = "GEMINI"

FINE_TUNED_GPT_MODEL = 'Fine-Tuned GPT'

DEFAULT_SYSTEM_MESSAGE = "You are a helpful assistant."

Expand Down Expand Up @@ -106,6 +108,11 @@ def get_agent_executor(
return get_google_agent_executor(
tools, llm, system_message, interrupt_before_action, CHECKPOINTER
)
elif agent == AgentType.FINE_TUNED_GPT_MODEL:
llm = get_openai_llm(fine_tuned_gpt=True)
return get_openai_agent_executor(
tools, llm, system_message, interrupt_before_action, CHECKPOINTER
)
else:
raise ValueError("Unexpected agent type")

Expand Down Expand Up @@ -175,6 +182,7 @@ class LLMType(str, Enum):
BEDROCK_CLAUDE2 = "Claude 2 (Amazon Bedrock)"
GEMINI = "GEMINI"
MIXTRAL = "Mixtral"
FINE_TUNED_GPT = "Fine-Tuned GPT"


def get_chatbot(
Expand All @@ -195,6 +203,8 @@ def get_chatbot(
llm = get_google_llm()
elif llm_type == LLMType.MIXTRAL:
llm = get_mixtral_fireworks()
elif llm_type == LLMType.FINE_TUNED_GPT:
llm = get_openai_llm(fine_tuned_gpt=True)
else:
raise ValueError("Unexpected llm type")
return get_chatbot_executor(llm, system_message, CHECKPOINTER)
Expand Down
8 changes: 7 additions & 1 deletion backend/app/llms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


@lru_cache(maxsize=4)
def get_openai_llm(gpt_4: bool = False, azure: bool = False):
def get_openai_llm(gpt_4: bool = False, azure: bool = False, fine_tuned_gpt: bool = False):
proxy_url = os.getenv("PROXY_URL")
http_client = None
if proxy_url:
Expand All @@ -31,6 +31,12 @@ def get_openai_llm(gpt_4: bool = False, azure: bool = False):
temperature=0,
streaming=True,
)
elif fine_tuned_gpt:
llm = ChatOpenAI(
model=os.environ["FINE_TUNED_GPT_MODEL"],
temperature=0,
streaming=True
)
else:
llm = ChatOpenAI(
http_client=http_client,
Expand Down