fix:添加mysql

上级 9711c0b3
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name=".langchain" uuid="6ed2f640-6bd4-426b-bab0-933c1e5074e0">
<driver-ref>sqlite.xerial</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
<jdbc-url>jdbc:sqlite:$PROJECT_DIR$/00-chartgpt/chainlit/.chainlit/.langchain.db</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="N802" />
</list>
</option>
</inspection_tool>
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredIdentifiers">
<list>
<option value="socketio.*" />
</list>
</option>
</inspection_tool>
</profile>
</component>
\ No newline at end of file
import os
import chainlit as cl
from langchain.chat_models import ChatOpenAI
from langchain.schema import (
HumanMessage,
......@@ -12,21 +11,14 @@ os.environ["OPENAI_API_KEY"] = '70846324f01c4e5cb3cc11da28a1e091'
os.environ["OPENAI_API_BASE"] = 'https://opencatgpt.openai.azure.com/'
os.environ["OPENAI_API_TYPE"] = 'azure'
os.environ["OPENAI_API_VERSION"] = '2023-05-15'
chat = ChatOpenAI(model_name="gpt-35-turbo", engine="gpt-35-turbo")
history = [SystemMessage(content="你是一个聊天机器人,请回答下列问题。\n")]
@cl.on_message # this function will be called every time a user inputs a message in the UI
@cl.on_message
async def main(message: str):
# history = [SystemMessage(content="你是一个聊天机器人,请回答下列问题。\n")]
history.append(HumanMessage(content=message))
res = await cl.make_async(sync_func)()
# res = chat(history)
# print(res.content)
# this is an intermediate step
# await cl.Message(author="Tool 1", content=f"Response from tool1", indent=1).send()
# send back the final answer
history.append(res)
await cl.Message(content=f"{res.content}").send()
......
import os
import chainlit as cl
from pymysql import Connection
from langchain.chat_models import ChatOpenAI
from langchain.schema import (
HumanMessage,
SystemMessage
)
# 构建到MySQL数据库的链接
conn = Connection(
host="localhost", # 主机名(IP)
port=3306, # 端口
user="root", # 账户
password="123456", # 密码
autocommit=True # 自动提交(确认)
)
# 公司的key
os.environ["OPENAI_API_KEY"] = '70846324f01c4e5cb3cc11da28a1e091'
os.environ["OPENAI_API_BASE"] = 'https://opencatgpt.openai.azure.com/'
os.environ["OPENAI_API_TYPE"] = 'azure'
os.environ["OPENAI_API_VERSION"] = '2023-05-15'
chat = ChatOpenAI(model_name="gpt-35-turbo", engine="gpt-35-turbo")
history = [SystemMessage(content="你是一个聊天机器人,请回答下列问题。\n")]
@cl.on_message
async def main(message: str):
history.append(HumanMessage(content=message))
res = await cl.make_async(sync_func)()
insert(message, res)
history.append(res)
await cl.Message(content=f"{res.content}").send()
def sync_func():
return chat(history)
def insert(que, res):
cursor = conn.cursor() # 获取到游标对象
# 选择数据库
conn.select_db("kwan")
# 执行sql
cursor.execute("insert into chatbot(question,response) values(que, res)")
# # 通过commit确认
# conn.commit()
# 关闭链接
conn.close()
import openai
import chainlit as cl
openai.proxy = 'http://127.0.0.1:8088'
openai.proxy = 'http://127.0.0.1:7890'
openai.api_key = "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"
model_name = "gpt-3.5-turbo"
settings = {
......
......@@ -38,13 +38,18 @@ class Solution:
if __name__ == '__main__':
l1 = ListNode(2)
l1.next = ListNode(4)
l1.next.next = ListNode(3)
l1 = ListNode(9)
l1.next = ListNode(9)
l1.next.next = ListNode(9)
l1.next.next.next = ListNode(9)
l1.next.next.next.next = ListNode(9)
l1.next.next.next.next.next = ListNode(9)
l1.next.next.next.next.next.next = ListNode(9)
l2 = ListNode(5)
l2.next = ListNode(6)
l2.next.next = ListNode(4)
l2 = ListNode(9)
l2.next = ListNode(9)
l2.next.next = ListNode(9)
l2.next.next.next = ListNode(9)
result = Solution().addTwoNumbers(l1, l2)
while result:
print(result.val, end=' -> ')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册