Approval of Python API for chat
The Endpoint:
Post by YYYY
Description: Exchange chat messages.Security: Requires Bearer Token for authentication.Request Schema ( ChatInput ) :
• message : string (The message from the client)
• chat_session_id : string, Optional (Existing session ID, if available)
• sender_id : string (Unique identifier for the sender)
Response Schema ( ChatResponse ) :
• chat_session_id : string (The unique session ID for the chat)
• response : string (The response message from the chatbot)
• file_url : string, Optional (URL of the file sent by the chatbot, if any)
Timestamp: datetime (Time when the response was generated)
• status_code : int (HTTP status code for the operation)
• sender_id : string (Unique identifier for the sender)
• receiver_id : string (Unique identifier for the receiver)
• transfer_to_agent : string (Whether the conversation should be transferred to a
live agent; values could be 'yes' or 'no')
• follow_up : string (Indicates whether this is a follow-up in an ongoing
A conversation or a new interaction.Acceptable values are 'yes' for follow-up
conversations and 'no' for new conversations.)From the source codes, for information:
The requirements.txt:
opened
The langchain
by pypdf
by langchain[docarray edit]
by TIKTOK
The Faiss-Cpu
Streaming
by streamlit-lottie
with dev-requirements.txt
flake8
by autopep8
The Dockerfile:
Use an official Python runtime as a parent image
from Python: 3.11
Set environment variables
by ARG OPENAI_API_KEY
ENV OPENAI_API_KEY=$OPENAI_API_KEY
Set the working directory in the container to /app
by YYYYYY
Add the current directory (i.e., everything) to the container's /app
Added .YYYY
Install any needed packages specified in requirements.txt
RUN pip install -r requirements.txt
Change the working directory to /app/src
by YYYYYY
# Make YYY port available to the world outside this container (Streamlit uses this port)
Exhibition YYYY
Run main.py when the container launches, this assumes that main.py is in the /app/src directory
CMD streamlit run main.py
by api.py :
from fastapi import FastAPI, HTTPException, Depends, Header
from pydantic import BaseModel
from typing import optional
from uuid import uuid4
from SAA.chat_session import ChatSession
Import of Datetime
App = FastAPI()
Sessions = {}
Class ChatInput (BaseModel):
Message by: str
chat_session_id: Optional[str] = None
by sender_id: str
Class ChatResponse (BaseModel):
chat_session_id by: str
Response to: str
file_url: Optional[str]
timestamp: datetime.datetime
The status_code: int
by sender_id: str
receiver_id: str
transfer_to_agent by: str
follow_up by: str
app.get (“YYYY”)
by def read_root():
return {”message”: “Hello, World!”
def get_token_header(token: str = header(...)):
secure_token = “YYY”
if token! = secure_token
raise HTTPException(status_code=400, detail="Invalid Token")
The return token
app.post (“YYYY”)
async def chat(input: ChatInput, response_model=ChatResponse, token: str = Depends(get_token_header)):
timestamp = datetime.datetime.now()
status_code = 200 # default status
Try to:
session_id = input.chat_session_id
if session_id and session_id in sessions:
existing_session = sessions[session_id]
existing_session.add_message(input.message)
Other is:
session_id = str(uuid4())
sessions[session_id] = ChatSession(”Hossam”, input.message)
response_text = sessions[session_id].get_last_response().lstrip(
“Sales Agent :”)
response_file_url = sessions[session_id].get_last_file_url()
Except for e:
status_code = YYYY
raise HTTPException(status_code=status_code, detail=str(e))
Return to {
“chat_session_id”: session_id
“response”: response_text
“file_url”: response_file_url
“Timestamp”: timestamp
“status_code”: status_code
“sender_id” means input.sender_id
“receiver_id”: “YYYY”
“transfer_to_agent”: “No”
The
(Some symbols removed, FLH broke)
Client's review of cooperation with Aleksandr B.
Approval of Python API for chatPython work has been done successfully.
Freelancer's review of cooperation with Sergey P
Approval of Python API for chatTwo tasks have been carried out on the project. Clear TZ and fast feedback.
I will be happy to cooperate further! and 🙂
-
5 days50 USD
4987 41 4 1 5 days50 USDThere is a great experience working with Telegram bots and creating a personal API on Python.
Write to LS for more detailed information.
-
3 days80 USD
294 3 1 3 days80 USDGreat experience in parsing (Selenium, BS4, API)
Great experience in Python. Django, Flask and FastAPI
Work with any databases (mySQL, PostgreSQL, Oracle, MongoDB) and file types.
Clean code according to all PEP8 instructions.
-
3 days49 USD
310 3 days49 USDHello to you! Ready to begin the task. Please provide the data on your site so that I can evaluate the work.
Current freelance projects in the category Python
Creation of a Human AI Assistant for Telegram groups### 1.1. Key Concept of the System The system must perform two main functions: #### 1. Client Communication Analysis The AI assistant must automatically analyze all communication in Telegram groups and understand the context of the conversation. In particular, the system… AI & Machine Learning, Python ∙ 22 hours 53 minutes back ∙ 35 proposals |
Black Ukraine (RP-project on base MTA)
1162 USD
|
Telegram automation of message distribution in chatsNeed to send messages to Telegram chats. To avoid bans. There are several hundred chats. To configure the frequency and variability of texts. Python, Bot Development ∙ 23 hours 46 minutes back ∙ 29 proposals |
Development of software with AIIt is necessary to develop software for automatic detection, capturing, and tracking of an object using a video camera and a rotating mechanism.Output data: Video camera with optics. Rotating device on two axes (azimuth/elevation angle). Servomotors controlled via Modbus… AI & Machine Learning, Python ∙ 2 days 6 hours back ∙ 17 proposals |
Automation of processes through API and PythonBelow I described the current process and the result I would like to achieve. I also attach files of the real process to better understand how it looks in reality Current process Currently, the entire process is performed manually: uploading/downloading files, transferring… AI & Machine Learning, Python ∙ 2 days 11 hours back ∙ 44 proposals |