Skip to content

Commit

Permalink
feat: select openAI model in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
NagariaHussain committed Jun 21, 2023
1 parent 085e962 commit e063dc9
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 2 deletions.
10 changes: 8 additions & 2 deletions doppio_bot/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from langchain.chains import ConversationChain
from langchain.prompts import PromptTemplate

OPENAI_MODEL_NAME = "gpt-3.5-turbo"

# Note: Copied the default template and added extra instructions for code output
prompt_template = PromptTemplate(
Expand Down Expand Up @@ -33,11 +32,12 @@ def get_chatbot_response(session_id: str, prompt_message: str) -> str:
# Throw if no key in site_config
# Maybe extract and cache this (site cache)
opeai_api_key = frappe.conf.get("openai_api_key")
openai_model = get_model_from_settings()

if not opeai_api_key:
frappe.throw("Please set `openai_api_key` in site config")

llm = OpenAI(model_name=OPENAI_MODEL_NAME, temperature=0, openai_api_key=opeai_api_key)
llm = OpenAI(model_name=openai_model, temperature=0, openai_api_key=opeai_api_key)
message_history = RedisChatMessageHistory(
session_id=session_id,
url=frappe.conf.get("redis_cache") or "redis://localhost:6379/0",
Expand All @@ -47,3 +47,9 @@ def get_chatbot_response(session_id: str, prompt_message: str) -> str:

response = conversation_chain.run(prompt_message)
return response


def get_model_from_settings():
return (
frappe.db.get_single_value("DoppioBot Settings", "openai_model") or "gpt-3.5-turbo"
)
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2023, Hussain Nagaria and contributors
// For license information, please see license.txt

// frappe.ui.form.on("DoppioBot Settings", {
// refresh(frm) {

// },
// });
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"actions": [],
"allow_rename": 1,
"creation": "2023-06-21 13:00:34.366049",
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"openai_model"
],
"fields": [
{
"default": "gpt-3.5-turbo",
"fieldname": "openai_model",
"fieldtype": "Select",
"label": "OpenAI Model",
"options": "gpt-3.5-turbo\ngpt-3.5-turbo-16k\ntext-davinci-003\ngpt-4\ngpt-4-32k"
}
],
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2023-06-21 13:06:09.895694",
"modified_by": "Administrator",
"module": "Frappe ChatGPT Integration",
"name": "DoppioBot Settings",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"print": 1,
"read": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2023, Hussain Nagaria and contributors
# For license information, please see license.txt

# import frappe
from frappe.model.document import Document


class DoppioBotSettings(Document):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2023, Hussain Nagaria and Contributors
# See license.txt

# import frappe
from frappe.tests.utils import FrappeTestCase


class TestDoppioBotSettings(FrappeTestCase):
pass

0 comments on commit e063dc9

Please sign in to comment.