a drop-in replacement for the standard streamlit textarea, offering enhanced autocomplete features powered by AI.
Project description
streamlit-copilot-textarea
a drop-in replacement for the standard streamlit textarea, offering enhanced autocomplete features powered by AI.
Installation
pip install streamlit-copilot-textarea
Usage
from streamlit_copilot_textarea import st_copilot_textarea
value = st_copilot_textarea(
prompt_template="please complete the text: {input_text}",
api_url="http://localhost:8000/generate",
requests_per_minute=20,
max_tokens=10,
stop=["\n", "."],
)
st.write(f"Your text: {value}")
prompt_template
: the prompt template to be sent to the api. It must contain{input_text}
, which will be replaced by the user input.api_url
: the url of the api to be used (see below for sever).requests_per_minute
: the number of requests per minute to be made to the api.max_tokens
: the maximum number of tokens to be generated.stop
: the tokens where the generation should stop.
server.py: fastapi example
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Payload(BaseModel):
prompt: str
# Add other fields that might be part of model_kwargs
temperature: Optional[float] = None
max_tokens: Optional[int] = None
@app.post("/generate")
async def generate(payload: Payload):
# here the prompt's {input_text} is already replaced with the user input.
prompt = payload.prompt
completion_text = request_chatgpt_here(prompt, payload.temperature, payload.max_tokens)
response = {"choices": [{"text": completion_text}]}
return response
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)
test your copilot api
curl -X POST "http://localhost:8000/generate" -H "Content-Type: application/json" -d '{"prompt": "please complete the text: Human and AI", "temperature": 0.5, "max_tokens": 10}'
Buiding from source
Prerequisites
- nodejs >= 18.x
- yarn >= 1.22.x
- poetry >= 1.2.x
- python >= 3.8.x
Building
./build.sh
Publishing
poetry publish
Thanks
License
This project is licensed under the MIT License - see the LICENSE file for details
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for streamlit_copilot_textarea-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 362b04fce4b51ea0f850e7f802a2573d9cc14fe00784da6511f094f75e97dbbc |
|
MD5 | 012b24d6c8d7ffd8b1f5283dfd3f7c49 |
|
BLAKE2b-256 | 5074e858e8cfae6e1fc7ea3e3318edd55a4fafd1d0d2555ff2ed6ecf3055195c |
Close
Hashes for streamlit_copilot_textarea-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3ca6aa0158cf50225e37ff2b247918b777bb49afce117cc188e41a6ced5e5b0 |
|
MD5 | 655bc7be3f5132c408a4309f1b726099 |
|
BLAKE2b-256 | ff31ecd6f7a8cb0f1dfee9325beb7e3df149d67f1a62caaf67829a798f549e7d |