Archived
1
0
Fork 0

Add langsmith

This commit is contained in:
Dianliang233 2023-09-11 17:46:54 +08:00
parent 551d88c90e
commit 5a330609ab
3 changed files with 134 additions and 120 deletions

View file

@ -21,6 +21,7 @@ curseforge_api_key =
exchange_rate_api_key =
wolfram_alpha_appid =
jwt_secret =
langsmith_api_key =
[cfg]
base_superuser = "QQ|2596322644"
@ -63,3 +64,5 @@ dice_output_len = 200
dice_detail_cnt = 5
dice_count_limit = 10
api_port = 5000
langsmith_endpoint = "https://api.smith.langchain.com"
langsmith_project =

View file

@ -1,17 +1,24 @@
import io
import os
import re
from decimal import Decimal
from PIL import Image as PILImage
from langchain.callbacks import get_openai_callback
from config import Config
from core.builtins import Bot, Plain, Image
from core.component import module
from core.dirty_check import check_bool, rickroll
from database import BotDBUtil
from .agent import agent_executor
from .formatting import generate_latex, generate_code_snippet
os.environ['LANGCHAIN_TRACING_V2'] = "true"
os.environ['LANGCHAIN_ENDPOINT'] = Config('langsmith_endpoint')
os.environ['LANGCHAIN_PROJECT'] = Config('langsmith_project')
os.environ['LANGCHAIN_API_KEY'] = Config('langsmith_api_key')
from langchain.callbacks import get_openai_callback # noqa: E402
from .agent import agent_executor # noqa: E402
from .formatting import generate_latex, generate_code_snippet # noqa: E402
ONE_K = Decimal('1000')
# https://openai.com/pricing
@ -27,7 +34,7 @@ CNY_TO_PETAL = 100
a = module('ask', developers=['Dianliang233'], desc='{ask.help.desc}')
@a.command('<question> {{ask.help}}')
@a.command('[--verbose] <question> {{ask.help}}')
@a.regex(r'^(?:question||问|問)[\:]\s?(.+?)[?]$', flags=re.I, desc='{ask.help.regex}')
async def _(msg: Bot.MessageSession):
is_superuser = msg.check_super_user()

View file

@ -1,6 +1,6 @@
from langchain.agents import AgentExecutor
from langchain.agents.openai_functions_agent.base import OpenAIFunctionsAgent
from langchain.callbacks.stdout import StdOutCallbackHandler
from langchain.callbacks import StdOutCallbackHandler
from langchain.chat_models import ChatOpenAI
from config import Config
@ -15,7 +15,11 @@ llm = ChatOpenAI(
'frequency_penalty': 0.0,
'presence_penalty': 0.0})
agent = OpenAIFunctionsAgent.from_llm_and_tools(llm=llm, tools=tools,
callback_manager=StdOutCallbackHandler, system_message=system_message)
agent = OpenAIFunctionsAgent.from_llm_and_tools(
llm=llm,
tools=tools,
callback_manager=[StdOutCallbackHandler],
system_message=system_message)
agent_executor = AgentExecutor.from_agent_and_tools(agent=agent, tools=tools, verbose=True)