Compare commits

..

10 Commits

Author SHA1 Message Date
ly 4d314c9714 实现进入页面后的提示问题功能。 2024-08-13 13:57:09 +08:00
ly 5b90e0a03e 修改代码检查问题 2024-08-13 13:49:06 +08:00
ly 9fdf3286d9 调整GIT提交忽略文件范围,增加对IDEA的排除和对生成后数据的排除。 2024-08-13 13:32:31 +08:00
ly c4062fbf48 修改关联提问提示文本为中文,同时增加上提问内容现定于知识库现有内容的要求。 2024-08-13 13:31:32 +08:00
ly de8673059c 还原原来的将本次回答检索到的知识库返回给客户端功能;
修改关联提问提示文本为中文,同时增加上提问内容现定于知识库现有内容的要求。
2024-08-13 13:30:57 +08:00
ly acf649beb2 还原原来的单行文本输入框 2024-08-13 13:29:33 +08:00
ly 9b3dfbbee4 调整前端页面右侧链接实现右对齐 2024-08-13 13:29:10 +08:00
ly 75f6f45b24 去除批处理中的python绝对路径 2024-08-13 13:28:10 +08:00
ly abbd116d25 增加环境配置示例文件 2024-08-13 13:27:17 +08:00
ly 20a6ad14a8 增加前端和后端依赖库版本锁定 2024-08-13 13:26:52 +08:00
17 changed files with 20995 additions and 18 deletions
+80
View File
@@ -0,0 +1,80 @@
# The Llama Cloud API key.
# LLAMA_CLOUD_API_KEY=
SQL_DATABASE_URL=mysql+pymysql://zjinfo1:Dy2Bcr53Hm5xRkba@110.42.234.166:3306/zjinfo1
#SQL_DATABASE_URL=mysql+pymysql://zjinfo2:GSKcziSdBixDXwcd@110.42.234.166:3306/zjinfo2
DASHSCOPE_API_KEY=sk-02c8540e86d84b7ca0e6f4f51bac6e60
# The provider for the AI models to use.
MODEL_PROVIDER=dashscope
# The name of LLM model to use.
MODEL=qwen-max
# 是否启用检索重排功能
ENABLE_RERANK=true
# Name of the embedding model to use.
EMBEDDING_MODEL=text-embedding-v2
# Dimension of the embedding model to use.
EMBEDDING_DIM=1024
# The questions to help users get started (multi-line).
CONVERSATION_STARTERS=本工程指什么?\n总算表有哪些费用?\n项目划分哪些内容构成?\n其他费用表有哪些内容?
# The OpenAI API key to use.
# OPENAI_API_KEY=
# Temperature for sampling from the model.
# LLM_TEMPERATURE=
# Maximum number of tokens to generate.
# LLM_MAX_TOKENS=
# The number of similar embeddings to return when retrieving documents.
TOP_K=5
# The time in milliseconds to wait for the stream to return a response.
STREAM_TIMEOUT=60000
# 向量存储数据库类型,目前可选:chroma、qdrant
VECTOR_STORE_TYPE=chroma
# The name of the collection in your vector database
VECTOR_STORE_COLLECTION=default
# The API endpoint for your vector database
# VECTOR_STORE_HOST=
# The port for your vector database
# VECTOR_STORE_PORT=
# The local path to the vector database.
# Specify this if you are using a local vector database.
# Otherwise, use VECTOR_STORE__HOST and VECTOR_STORE__PORT config above
VECTOR_STORE_PATH=./storage_vector
PHOENIX_API_KEY=123456
PHOENIX_URL=http://localhost:6006/v1/traces
PHOENIX_PROJECT_NAME=ly_zjapp
#OTEL_SERVICE_NAME=ly_zjapp
#OTEL_RESOURCE_ATTRIBUTES=openinference.project.name=ly_zjapp
# The address to start the backend app.
APP_HOST=0.0.0.0
# The port to start the backend app.
APP_PORT=8000
FILESERVER_URL_PREFIX=/api/files
# E2B_API_KEY key is required to run code interpreter tool. Get it here: https://e2b.dev/docs/getting-started/api-key
# E2B_API_KEY=
# The system prompt for the AI model.
SYSTEM_PROMPT="You are a weather forecast agent. You help users to get the weather forecast for a given location.
-You are a Python interpreter that can run any python code in a secure environment.
- The python code runs in a Jupyter notebook. Every time you call the 'interpreter' tool, the python code is executed in a separate cell.
- You are given tasks to complete and you run python code to solve them.
- It's okay to make multiple calls to interpreter tool. If you get an error or the result is not what you expected, you can call the tool again. Don't give up too soon!
- Plot visualizations using matplotlib or any other visualization library directly in the notebook.
- You can install any pip package (if it exists) by running a cell with pip install.
"
+3
View File
@@ -2,3 +2,6 @@ __pycache__
storage storage
.env .env
output output
/storage_vector/
/.idea/
/.python-version
+1 -1
View File
@@ -124,7 +124,7 @@ async def chat_config() -> ChatConfig:
starter_questions = None starter_questions = None
conversation_starters = os.getenv("CONVERSATION_STARTERS") conversation_starters = os.getenv("CONVERSATION_STARTERS")
if conversation_starters and conversation_starters.strip(): if conversation_starters and conversation_starters.strip():
starter_questions = conversation_starters.strip().split("\n") starter_questions = conversation_starters.strip().split("\\n")
return ChatConfig(starter_questions=starter_questions) return ChatConfig(starter_questions=starter_questions)
+4 -3
View File
@@ -4,7 +4,7 @@ from typing import Any, Dict, List, Literal, Optional, Set
from llama_index.core.llms import ChatMessage, MessageRole from llama_index.core.llms import ChatMessage, MessageRole
from llama_index.core.schema import NodeWithScore from llama_index.core.schema import NodeWithScore
from pydantic import BaseModel, Field, validator from pydantic import BaseModel, Field, validator, field_validator
from pydantic.alias_generators import to_camel from pydantic.alias_generators import to_camel
logger = logging.getLogger("uvicorn") logger = logging.getLogger("uvicorn")
@@ -89,7 +89,7 @@ class ChatData(BaseModel):
} }
} }
@validator("messages") @field_validator("messages")
def messages_must_not_be_empty(cls, v): def messages_must_not_be_empty(cls, v):
if len(v) == 0: if len(v) == 0:
raise ValueError("Messages must not be empty") raise ValueError("Messages must not be empty")
@@ -173,7 +173,8 @@ class SourceNodes(BaseModel):
def from_source_node(cls, source_node: NodeWithScore): def from_source_node(cls, source_node: NodeWithScore):
metadata = source_node.node.metadata metadata = source_node.node.metadata
url = cls.get_url_from_metadata(metadata) url = cls.get_url_from_metadata(metadata)
text = 'filename' in metadata and metadata['filename'] or source_node.node.node_id #text = 'filename' in metadata and metadata['filename'] or source_node.node.node_id
text = source_node.node.text
return cls( return cls(
id=source_node.node.node_id, id=source_node.node.node_id,
metadata=metadata, metadata=metadata,
+3 -3
View File
@@ -6,10 +6,10 @@ from llama_index.core.settings import Settings
from pydantic import BaseModel from pydantic import BaseModel
NEXT_QUESTIONS_SUGGESTION_PROMPT = PromptTemplate( NEXT_QUESTIONS_SUGGESTION_PROMPT = PromptTemplate(
"You're a helpful assistant! Your task is to suggest the next question that user might ask. " "你是一个乐于助人的助手!你的任务是对用户可能会问的下一个问题给出建议。 "
"\nHere is the conversation history" "\n这是对话历史记录"
"\n---------------------\n{conversation}\n---------------------" "\n---------------------\n{conversation}\n---------------------"
"Given the conversation history, please give me $number_of_questions questions that you might ask next!" "考虑到对话历史记录,仅限于现在知识库已有内容, 请给我 $number_of_questions 个你接下来可能会问题的问题!"
) )
N_QUESTION_TO_GENERATE = 3 N_QUESTION_TO_GENERATE = 3
+3979
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1,4 +1,4 @@
rmdir /S /Q storage_vector rmdir /S /Q storage_vector
rmdir /S /Q storage rmdir /S /Q storage
C:\Users\liuyue\AppData\Local\pypoetry\Cache\virtualenvs\app-laEO4lY0-py3.11\Scripts\python app/engine/generate.py python app/engine/generate.py
+1 -1
View File
@@ -1,4 +1,4 @@
rmdir /S /Q storage_vector rmdir /S /Q storage_vector
rmdir /S /Q storage rmdir /S /Q storage
C:\Users\liuyue\AppData\Local\pypoetry\Cache\virtualenvs\app-laEO4lY0-py3.11\Scripts\python tests/query.py python tests/query.py
+1 -1
View File
@@ -1 +1 @@
C:\Users\liuyue\AppData\Local\pypoetry\Cache\virtualenvs\app-laEO4lY0-py3.11\Scripts\python main.py python main.py
+10
View File
@@ -0,0 +1,10 @@
# The backend API for chat endpoint.
#NEXT_PUBLIC_CHAT_API=http://localhost:8000/api/chat
NEXT_PUBLIC_CHAT_API=http://10.1.6.41:8000/api/chat
#PHOENIX_SERVER_URL=http://localhost:6006/
PHOENIX_SERVER_URL=http://10.1.6.41:6006/
# Let's the user change indexes in LlamaCloud projects
NEXT_PUBLIC_USE_LLAMACLOUD=false
+1 -1
View File
@@ -4,7 +4,7 @@ const phoenixUrl = process.env.PHOENIX_SERVER_URL;
export default function Header() { export default function Header() {
return ( return (
<div className="z-10 max-w-5xl w-full items-center justify-between font-mono text-sm lg:flex"> <div className="z-10 w-full items-center justify-between font-mono text-sm lg:flex">
<p className="fixed left-0 top-0 flex w-full justify-center border-b border-gray-300 bg-gradient-to-b from-zinc-200 pb-6 pt-8 backdrop-blur-2xl dark:border-neutral-800 dark:bg-zinc-800/30 dark:from-inherit lg:static lg:w-auto lg:rounded-xl lg:border lg:bg-gray-200 lg:p-4 lg:dark:bg-zinc-800/30"> <p className="fixed left-0 top-0 flex w-full justify-center border-b border-gray-300 bg-gradient-to-b from-zinc-200 pb-6 pt-8 backdrop-blur-2xl dark:border-neutral-800 dark:bg-zinc-800/30 dark:from-inherit lg:static lg:w-auto lg:rounded-xl lg:border lg:bg-gray-200 lg:p-4 lg:dark:bg-zinc-800/30">
<code className="font-mono font-bold"><a href="javascript:location.reload();"></a></code> <code className="font-mono font-bold"><a href="javascript:location.reload();"></a></code>
</p> </p>
@@ -99,9 +99,8 @@ export default function ChatInput(
</div> </div>
)} )}
<div className="flex w-full items-start justify-between gap-4 "> <div className="flex w-full items-start justify-between gap-4 ">
<textarea <Input
autoFocus autoFocus
rows={2}
name="message" name="message"
placeholder="请输入消息" placeholder="请输入消息"
className="flex-1" className="flex-1"
@@ -127,9 +127,26 @@ function NodeInfo({ nodeInfo }: { nodeInfo: NodeInfo }) {
} }
// node generated by unknown loader, implement renderer by analyzing logged out metadata // node generated by unknown loader, implement renderer by analyzing logged out metadata
// return (
// <p>
// 对不起, 未知文件类型. 无法打开当前的来源文件。
// </p>
// );
return ( return (
<p> <div className="flex items-center my-2">
, . <span>{nodeInfo.text}</span>
</p> <Button
onClick={() => copyToClipboard(nodeInfo.url!)}
size="icon"
variant="ghost"
className="h-12 w-12 shrink-0"
>
{isCopied ? (
<Check className="h-4 w-4" />
) : (
<Copy className="h-4 w-4" />
)}
</Button>
</div>
); );
} }
@@ -10,7 +10,7 @@ export interface ChatHandler {
data?: any; data?: any;
}, },
) => void; ) => void;
handleInputChange: (e: React.ChangeEvent<HTMLTextAreaElement>) => void; handleInputChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
reload?: () => void; reload?: () => void;
stop?: () => void; stop?: () => void;
onFileUpload?: (file: File) => Promise<void>; onFileUpload?: (file: File) => Promise<void>;
+16885
View File
File diff suppressed because it is too large Load Diff
+3
View File
@@ -0,0 +1,3 @@
ENV_PHOENIX_HOST=0.0.0.0
ENV_PHOENIX_PORT=6006
PHOENIX_HOST_ROOT_PATH=./.phoenix/
+1 -1
View File
@@ -2,4 +2,4 @@ SET ENV_PHOENIX_HOST=0.0.0.0
SET ENV_PHOENIX_PORT=6006 SET ENV_PHOENIX_PORT=6006
SET PHOENIX_HOST_ROOT_PATH=./.phoenix/ SET PHOENIX_HOST_ROOT_PATH=./.phoenix/
C:\Users\liuyue\AppData\Local\pypoetry\Cache\virtualenvs\app-pCyqx0Uo-py3.11\Scripts\python phoenixserver.py python phoenixserver.py