Skip to content
Snippets Groups Projects
Verified Commit edc34fe9 authored by 学津 刘's avatar 学津 刘 :star2:
Browse files

feat: poetry add

parent c93d85d1
No related branches found
Tags 0.2.9
No related merge requests found
.DS_Store 0 → 100644
File added
.idea
\ No newline at end of file
__pycache__
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<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="N801" />
</list>
</option>
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (llm-server)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/llm-server.iml" filepath="$PROJECT_DIR$/.idea/llm-server.iml" />
</modules>
</component>
</project>
\ No newline at end of file
FROM python:3.11-slim
RUN pip install poetry==1.6.1
RUN poetry config virtualenvs.create false
WORKDIR /code
COPY ./pyproject.toml ./README.md ./poetry.lock* ./
COPY ./package[s] ./packages
RUN poetry install --no-interaction --no-ansi --no-root
COPY ./app ./app
RUN poetry install --no-interaction --no-ansi
EXPOSE 8080
CMD exec uvicorn app.server:app --host 0.0.0.0 --port 8080
# llm-server
## Installation
Install the LangChain CLI if you haven't yet
```bash
pip install -U langchain-cli
```
## Adding packages
```bash
# adding packages from
# https://github.com/langchain-ai/langchain/tree/master/templates
langchain app add $PROJECT_NAME
# adding custom GitHub repo packages
langchain app add --repo $OWNER/$REPO
# or with whole git string (supports other git providers):
# langchain app add git+https://github.com/hwchase17/chain-of-verification
# with a custom api mount point (defaults to `/{package_name}`)
langchain app add $PROJECT_NAME --api_path=/my/custom/path/rag
```
Note: you remove packages by their api path
```bash
langchain app remove my/custom/path/rag
```
## Setup LangSmith (Optional)
LangSmith will help us trace, monitor and debug LangChain applications.
LangSmith is currently in private beta, you can sign up [here](https://smith.langchain.com/).
If you don't have access, you can skip this section
```shell
export LANGCHAIN_TRACING_V2=true
export LANGCHAIN_API_KEY=<your-api-key>
export LANGCHAIN_PROJECT=<your-project> # if not specified, defaults to "default"
```
## Launch LangServe
```bash
langchain serve
```
## Running in Docker
This project folder includes a Dockerfile that allows you to easily build and host your LangServe app.
### Building the Image
To build the image, you simply:
```shell
docker build . -t my-langserve-app
```
If you tag your image with something other than `my-langserve-app`,
note it for use in the next step.
### Running the Image Locally
To run the image, you'll need to include any environment variables
necessary for your application.
In the below example, we inject the `OPENAI_API_KEY` environment
variable with the value set in my local environment
(`$OPENAI_API_KEY`)
We also expose port 8080 with the `-p 8080:8080` option.
```shell
docker run -e OPENAI_API_KEY=$OPENAI_API_KEY -p 8080:8080 my-langserve-app
```
File added
from fastapi import FastAPI
from fastapi.responses import RedirectResponse
from langchain_community.chat_models import QianfanChatEndpoint
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langserve import add_routes
from langchain.chat_models import ChatAnthropic, ChatOpenAI
import os
app = FastAPI()
@app.get("/")
async def redirect_root_to_docs():
return RedirectResponse("/docs")
# Edit this to add the chain you want to add
# add_routes(app, NotImplemented)
os.environ["QIANFAN_AK"] = "8YbeFqJnwIQcCpSQle71OCZR"
os.environ["QIANFAN_SK"] = "mCMGf98ToWtDWIHUgHdkqDAIwP21dVwF"
prompt = ChatPromptTemplate.from_template(
"请你根据"
"指定contributor和其他relatedContributor之间的关系、"
"指定contributor和其参与的相关仓库,"
"对该contributor可能存在的人物关系、擅长领域、成长轨迹进行分析。"
"下面是所给关系,"
"其中核心人物的信息包括在最外层contributorProfileVO中,"
"与其相关的其他人物在relatedContributor中,"
"与其相关的仓库在relatedProjects中:"
"{info}")
model = QianfanChatEndpoint(model="ERNIE-Lite-8K-0922")
output_parser = StrOutputParser()
chain = prompt | model | output_parser
add_routes(
app,
chain,
path="/llm",
)
# add_routes(
# app,
# ChatAnthropic(),
# path="/anthropic",
# )
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)
......@@ -6,6 +6,7 @@ import json
import os
from langchain.llms import QianfanLLMEndpoint
os.environ["QIANFAN_AK"] = "8YbeFqJnwIQcCpSQle71OCZR"
os.environ["QIANFAN_SK"] = "mCMGf98ToWtDWIHUgHdkqDAIwP21dVwF"
......
{
"contributorProfileVO": {
"contributor": {
"id": 17426603,
"name": "bjorn3",
"repos": []
},
"identity": null,
"initialMotivation": null,
"difficultyChoice": "hardcore"
},
"relatedContributor": [
{
"relation": "Coworker",
"contributorProfileVO": {
"contributor": {
"id": 762626,
"name": "nrc",
"repos": []
},
"identity": null,
"initialMotivation": null,
"difficultyChoice": "hardcore"
}
},
{
"relation": "Coworker",
"contributorProfileVO": {
"contributor": {
"id": 77424,
"name": "eddyb",
"repos": []
},
"identity": null,
"initialMotivation": null,
"difficultyChoice": "hardcore"
}
},
{
"relation": "Coworker",
"contributorProfileVO": {
"contributor": {
"id": 64996,
"name": "alexcrichton",
"repos": []
},
"identity": null,
"initialMotivation": null,
"difficultyChoice": "hardcore"
}
}
],
"relatedProjects": [
{
"projectId": 72148881,
"projectName": "cretonne",
"text": "Cretonne code generator",
"language": "Rust",
"stars": 0,
"forks": 0,
"ownerId": 762626,
"createdAt": "2016-10-27T21:15:46Z",
"updatedAt": "2019-11-12T16:01:17Z"
},
{
"projectId": 73821518,
"projectName": "cretonne",
"text": "Cretonne code generator",
"language": "Rust",
"stars": 0,
"forks": 0,
"ownerId": 1506030,
"createdAt": "2016-11-15T14:30:32Z",
"updatedAt": "2019-11-12T16:01:17Z"
},
{
"projectId": 91002761,
"projectName": "cretonne",
"text": "Cretonne code generator",
"language": "Rust",
"stars": 0,
"forks": 1,
"ownerId": 17426603,
"createdAt": "2017-05-11T16:52:19Z",
"updatedAt": "2019-11-12T16:01:23Z"
},
{
"projectId": 102633739,
"projectName": "cretonne",
"text": "Cretonne code generator",
"language": "Rust",
"stars": 0,
"forks": 0,
"ownerId": 311082,
"createdAt": "2017-09-06T16:44:33Z",
"updatedAt": "2019-11-12T16:01:25Z"
},
{
"projectId": 128963742,
"projectName": "cretonne",
"text": "Cretonne code generator",
"language": "Rust",
"stars": 0,
"forks": 0,
"ownerId": 278509,
"createdAt": "2018-04-10T16:29:25Z",
"updatedAt": "2019-11-12T16:01:26Z"
},
{
"projectId": 137083500,
"projectName": "cretonne",
"text": "Cretonne code generator",
"language": "Rust",
"stars": 0,
"forks": 0,
"ownerId": 77424,
"createdAt": "2018-06-12T14:26:57Z",
"updatedAt": "2019-11-12T16:01:28Z"
},
{
"projectId": 72148881,
"projectName": "cretonne",
"text": "Cretonne code generator",
"language": "Rust",
"stars": 0,
"forks": 0,
"ownerId": 762626,
"createdAt": "2016-10-27T21:15:46Z",
"updatedAt": "2019-11-12T16:01:17Z"
},
{
"projectId": 73821518,
"projectName": "cretonne",
"text": "Cretonne code generator",
"language": "Rust",
"stars": 0,
"forks": 0,
"ownerId": 1506030,
"createdAt": "2016-11-15T14:30:32Z",
"updatedAt": "2019-11-12T16:01:17Z"
},
{
"projectId": 91002761,
"projectName": "cretonne",
"text": "Cretonne code generator",
"language": "Rust",
"stars": 0,
"forks": 1,
"ownerId": 17426603,
"createdAt": "2017-05-11T16:52:19Z",
"updatedAt": "2019-11-12T16:01:23Z"
},
{
"projectId": 102633739,
"projectName": "cretonne",
"text": "Cretonne code generator",
"language": "Rust",
"stars": 0,
"forks": 0,
"ownerId": 311082,
"createdAt": "2017-09-06T16:44:33Z",
"updatedAt": "2019-11-12T16:01:25Z"
},
{
"projectId": 128963742,
"projectName": "cretonne",
"text": "Cretonne code generator",
"language": "Rust",
"stars": 0,
"forks": 0,
"ownerId": 278509,
"createdAt": "2018-04-10T16:29:25Z",
"updatedAt": "2019-11-12T16:01:26Z"
},
{
"projectId": 137083500,
"projectName": "cretonne",
"text": "Cretonne code generator",
"language": "Rust",
"stars": 0,
"forks": 0,
"ownerId": 77424,
"createdAt": "2018-06-12T14:26:57Z",
"updatedAt": "2019-11-12T16:01:28Z"
},
{
"projectId": 75509095,
"projectName": "addr2line",
"text": "A cross-platform `addr2line` clone written in Rust, using `gimli`",
"language": "Rust",
"stars": 0,
"forks": 0,
"ownerId": 176295,
"createdAt": "2016-12-04T00:43:48Z",
"updatedAt": "2016-12-04T00:43:49Z"
},
{
"projectId": 110479243,
"projectName": "addr2line",
"text": "A cross-platform `addr2line` clone written in Rust, using `gimli`",
"language": "Rust",
"stars": 0,
"forks": 0,
"ownerId": 1455697,
"createdAt": "2017-11-12T23:48:35Z",
"updatedAt": "2017-11-12T23:48:36Z"
},
{
"projectId": 135768479,
"projectName": "addr2line",
"text": "A cross-platform `addr2line` clone written in Rust, using `gimli`",
"language": "Rust",
"stars": 0,
"forks": 0,
"ownerId": 8872119,
"createdAt": "2018-06-01T22:26:08Z",
"updatedAt": "2018-06-07T01:02:25Z"
},
{
"projectId": 159392005,
"projectName": "addr2line",
"text": "A cross-platform `addr2line` clone written in Rust, using `gimli`",
"language": "Rust",
"stars": 0,
"forks": 0,
"ownerId": 36186,
"createdAt": "2018-11-27T20:01:55Z",
"updatedAt": "2018-11-27T20:01:57Z"
},
{
"projectId": 181285860,
"projectName": "addr2line",
"text": "A cross-platform `addr2line` clone written in Rust, using `gimli`",
"language": "Rust",
"stars": 0,
"forks": 0,
"ownerId": 17426603,
"createdAt": "2019-04-14T09:22:51Z",
"updatedAt": "2019-04-14T09:22:54Z"
},
{
"projectId": 194045464,
"projectName": "addr2line",
"text": "A cross-platform `addr2line` clone written in Rust, using `gimli`",
"language": "Rust",
"stars": 0,
"forks": 0,
"ownerId": 64996,
"createdAt": "2019-06-27T07:30:49Z",
"updatedAt": "2019-06-27T07:30:52Z"
},
{
"projectId": 340503125,
"projectName": "addr2line",
"text": "A cross-platform `addr2line` clone written in Rust, using `gimli`",
"language": "Rust",
"stars": 0,
"forks": 0,
"ownerId": 37087391,
"createdAt": "2021-02-19T22:19:23Z",
"updatedAt": "2021-02-19T22:23:07Z"
},
{
"projectId": 486056548,
"projectName": "addr2line",
"text": "A cross-platform `addr2line` clone written in Rust, using `gimli`",
"language": "Rust",
"stars": 0,
"forks": 0,
"ownerId": 12389383,
"createdAt": "2022-04-27T05:23:36Z",
"updatedAt": "2022-04-25T16:39:47Z"
},
{
"projectId": 602792287,
"projectName": "addr2line",
"text": "A cross-platform `addr2line` clone written in Rust, using `gimli`",
"language": "Rust",
"stars": 0,
"forks": 0,
"ownerId": 72159,
"createdAt": "2023-02-17T00:20:53Z",
"updatedAt": "2023-02-15T20:29:38Z"
},
{
"projectId": 751007475,
"projectName": "addr2line",
"text": "A cross-platform `addr2line` clone written in Rust, using `gimli`",
"language": "Rust",
"stars": 0,
"forks": 0,
"ownerId": 115040,
"createdAt": "2024-01-31T18:50:22Z",
"updatedAt": "2024-01-31T18:50:22Z"
}
]
}
\ No newline at end of file
# This is a sample Python script.
# Press ⌃R to execute it or replace it with your code.
# Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings.
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press ⌘F8 to toggle the breakpoint.
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
print_hi('PyCharm')
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
[tool.poetry]
name = "llm-server"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
readme = "README.md"
packages = [
{ include = "app" },
]
[tool.poetry.dependencies]
python = "^3.11"
uvicorn = "^0.23.2"
langserve = {extras = ["server"], version = ">=0.0.30"}
pydantic = "<2"
[tool.poetry.group.dev.dependencies]
langchain-cli = ">=0.0.15"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment