init commit to huggine face
Browse files- .idea/workspace.xml +56 -0
- Dockerfile +11 -0
- app.py +45 -0
- chainlit.md +14 -0
- requirements.txt +2 -0
.idea/workspace.xml
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="AutoImportSettings">
|
| 4 |
+
<option name="autoReloadType" value="SELECTIVE" />
|
| 5 |
+
</component>
|
| 6 |
+
<component name="ChangeListManager">
|
| 7 |
+
<list default="true" id="42da0b62-0228-474b-ab54-9cfd76be286f" name="Changes" comment="">
|
| 8 |
+
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
|
| 9 |
+
</list>
|
| 10 |
+
<option name="SHOW_DIALOG" value="false" />
|
| 11 |
+
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
| 12 |
+
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
| 13 |
+
<option name="LAST_RESOLUTION" value="IGNORE" />
|
| 14 |
+
</component>
|
| 15 |
+
<component name="Git.Settings">
|
| 16 |
+
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
| 17 |
+
</component>
|
| 18 |
+
<component name="MarkdownSettingsMigration">
|
| 19 |
+
<option name="stateVersion" value="1" />
|
| 20 |
+
</component>
|
| 21 |
+
<component name="ProjectId" id="2V0PR6MQWdsQffTUXL2DLnDAaPy" />
|
| 22 |
+
<component name="ProjectViewState">
|
| 23 |
+
<option name="hideEmptyMiddlePackages" value="true" />
|
| 24 |
+
<option name="showLibraryContents" value="true" />
|
| 25 |
+
</component>
|
| 26 |
+
<component name="PropertiesComponent"><![CDATA[{
|
| 27 |
+
"keyToString": {
|
| 28 |
+
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
| 29 |
+
"RunOnceActivity.ShowReadmeOnStart": "true",
|
| 30 |
+
"WebServerToolWindowFactoryState": "false",
|
| 31 |
+
"git-widget-placeholder": "main",
|
| 32 |
+
"last_opened_file_path": "/Users/jiefeng/Dropbox/Apps/llm-app",
|
| 33 |
+
"node.js.detected.package.eslint": "true",
|
| 34 |
+
"node.js.detected.package.tslint": "true",
|
| 35 |
+
"node.js.selected.package.eslint": "(autodetect)",
|
| 36 |
+
"node.js.selected.package.tslint": "(autodetect)",
|
| 37 |
+
"nodejs_package_manager_path": "npm",
|
| 38 |
+
"vue.rearranger.settings.migration": "true"
|
| 39 |
+
}
|
| 40 |
+
}]]></component>
|
| 41 |
+
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
| 42 |
+
<component name="TaskManager">
|
| 43 |
+
<task active="true" id="Default" summary="Default task">
|
| 44 |
+
<changelist id="42da0b62-0228-474b-ab54-9cfd76be286f" name="Changes" comment="" />
|
| 45 |
+
<created>1693970012531</created>
|
| 46 |
+
<option name="number" value="Default" />
|
| 47 |
+
<option name="presentableId" value="Default" />
|
| 48 |
+
<updated>1693970012531</updated>
|
| 49 |
+
<workItem from="1693970014286" duration="1103000" />
|
| 50 |
+
</task>
|
| 51 |
+
<servers />
|
| 52 |
+
</component>
|
| 53 |
+
<component name="TypeScriptGeneratedFilesManager">
|
| 54 |
+
<option name="version" value="3" />
|
| 55 |
+
</component>
|
| 56 |
+
</project>
|
Dockerfile
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.9
|
| 2 |
+
RUN useradd -m -u 1000 user
|
| 3 |
+
USER user
|
| 4 |
+
ENV HOME=/home/user \
|
| 5 |
+
PATH=/home/user/.local/bin:$PATH
|
| 6 |
+
WORKDIR $HOME/app
|
| 7 |
+
COPY --chown=user . $HOME/app
|
| 8 |
+
COPY ./requirements.txt ~/app/requirements.txt
|
| 9 |
+
RUN pip install -r requirements.txt
|
| 10 |
+
COPY . .
|
| 11 |
+
CMD ["chainlit", "run", "app.py", "--port", "7860"]
|
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# You can find this code for Chainlit python streaming here (https://docs.chainlit.io/concepts/streaming/python)
|
| 2 |
+
|
| 3 |
+
# OpenAI Chat completion
|
| 4 |
+
|
| 5 |
+
import openai #importing openai for API usage
|
| 6 |
+
import chainlit as cl #importing chainlit for our app
|
| 7 |
+
|
| 8 |
+
# You only need the api key inserted here if it's not in your .env file
|
| 9 |
+
#openai.api_key = "YOUR_API_KEY"
|
| 10 |
+
|
| 11 |
+
# We select our model. If you do not have access to GPT-4, please use GPT-3.5T (gpt-3.5-turbo)
|
| 12 |
+
|
| 13 |
+
model_name = "gpt-3.5-turbo"
|
| 14 |
+
# model_name = "gpt-4"
|
| 15 |
+
settings = {
|
| 16 |
+
"temperature": 0.7, # higher value increases output diveresity/randomness
|
| 17 |
+
"max_tokens": 500, # maximum length of output response
|
| 18 |
+
"top_p": 1, # choose only the top x% of possible words to return
|
| 19 |
+
"frequency_penalty": 0, # higher value will result in the model being more conservative in its use of repeated tokens.
|
| 20 |
+
"presence_penalty": 0, # higher value will result in the model being more likely to generate tokens that have not yet been included in the generated text
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
@cl.on_chat_start # marks a function that will be executed at the start of a user session
|
| 24 |
+
def start_chat():
|
| 25 |
+
cl.user_session.set(
|
| 26 |
+
"message_history",
|
| 27 |
+
[{"role": "system", "content": "You are a helpful assistant."}],
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
@cl.on_message # marks a function that should be run each time the chatbot receives a message from a user
|
| 32 |
+
async def main(message: str):
|
| 33 |
+
message_history = cl.user_session.get("message_history")
|
| 34 |
+
message_history.append({"role": "user", "content": message})
|
| 35 |
+
|
| 36 |
+
msg = cl.Message(content="")
|
| 37 |
+
|
| 38 |
+
async for stream_resp in await openai.ChatCompletion.acreate(
|
| 39 |
+
model=model_name, messages=message_history, stream=True, **settings
|
| 40 |
+
):
|
| 41 |
+
token = stream_resp.choices[0]["delta"].get("content", "")
|
| 42 |
+
await msg.stream_token(token)
|
| 43 |
+
|
| 44 |
+
message_history.append({"role": "assistant", "content": msg.content})
|
| 45 |
+
await msg.send()
|
chainlit.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Welcome to Chainlit! ππ€
|
| 2 |
+
|
| 3 |
+
Hi there, Developer! π We're excited to have you on board. Chainlit is a powerful tool designed to help you prototype, debug and share applications built on top of LLMs.
|
| 4 |
+
|
| 5 |
+
## Useful Links π
|
| 6 |
+
|
| 7 |
+
- **Documentation:** Get started with our comprehensive [Chainlit Documentation](https://docs.chainlit.io) π
|
| 8 |
+
- **Discord Community:** Join our friendly [Chainlit Discord](https://discord.gg/k73SQ3FyUh) to ask questions, share your projects, and connect with other developers! π¬
|
| 9 |
+
|
| 10 |
+
We can't wait to see what you create with Chainlit! Happy coding! π»π
|
| 11 |
+
|
| 12 |
+
## Welcome screen
|
| 13 |
+
|
| 14 |
+
To modify the welcome screen, edit the `chainlit.md` file at the root of your project. If you do not want a welcome screen, just leave this file empty.
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
chainlit
|
| 2 |
+
openai
|