Sign inSign up

gptstonks/api

By gptstonks

โ€ขUpdated over 2 years ago

GPTStonks Chat Community Edition official API

Image
0

1.6K

gptstonks/api repository overview

Logo

Join Waitlist Badge Youtube Channel Badge X Follow Us Badge Discord Badge Docker Badge โ 

Hugging Face Badge LangChain Badge โ  FastAPI Badge โ  OpenBB Badge โ 

โ GPTStonks Chatbot API

Welcome to the GPTStonks Chatbot API documentation! This API allows you to interact with a powerful financial chatbot built on top of the openbb framework. Whether you're a developer looking to integrate financial chat capabilities into your application or a trader seeking automated financial insights, this API is designed to provide you with a seamless and customizable experience.

โ Table of Contents

  • GPTStonks Chatbot API
    • Table of Contents
    • Introduction ๐ŸŒŸ
    • Features ๐Ÿš€
    • Supported LLM Providers
    • Supported Embeddings Providers
    • Getting Started ๐Ÿ› ๏ธ
      • Prerequisites
      • Full deployment [api + frontend + db] (recommended)
      • Installation ๐Ÿ›ธ
    • For Production Environments ๐Ÿญ
    • Usage๐Ÿ’ก
    • API Endpoints๐ŸŒ
    • Configuration with environment variables โš™๏ธ
    • Contributing ๐Ÿค
    • License ๐Ÿ“ƒ

โ Introduction ๐ŸŒŸ

GPTStonks is a financial chatbot powered by LLMs and enhanced with the openbb framework. It provides natural language conversation capabilities for financial topics, making it an ideal choice for a wide range of financial applications, including:

  • Learning about the financial markets
  • Improving trading strategies
  • Financial news analysis: sentiment, trends, etc.
  • Customer support for financial institutions

This API allows you to integrate the GPTStonks financial chatbot into your projects, enabling real-time financial chat interactions with users.

โ Features ๐Ÿš€

  • Real-time Financial Chat: Engage in natural language conversations about financial topics.
  • Customizable Responses: Tailor the chatbot's responses to suit your specific use case.
  • Easy Integration: Built on FastAPI, this API is designed for straightforward integration into your application or platform.
  • Extensive Documentation: Detailed documentation and examples to help you get started quickly.

โ Supported LLM Providers

  • Llama.cppโ : optimized implementations of the most popular open source LLMs for inference over CPU and GPU. See their docs for more details on supported models, which include Mixtral, Llama 2 and Zephyr among others. Many quantized models (GGUF) can be found in Hugging Face under the user TheBlokeโ .
  • Amazon Bedrockโ : foundation models from a variety of providers, including Anthropic and Amazon.
  • OpenAIโ : GPT family of foundation models. For now only instruct versions are supported, such as gpt-3.5-turbo-instruct. Chat versions will be added soon.
  • Vertex AIโ : similar to Amazon Bedrock but provided by Google. This integration is in alpha version, not recommended for now.

โ Supported Embeddings Providers

โ Getting Started ๐Ÿ› ๏ธ

โ Prerequisites

Before you begin, make sure you have Dockerโ  installed on your system.

  1. Clone this repository to your local machine:
git clone https://github.com/gptstonks/api.git
  1. Check the .env.template file for the required environment variables. Modify the values as desired and save the file.

  2. Run the docker-compose file:

docker-compose up
  1. If you didn't change any port configuration, navigate to http://localhost:3000 to access the frontend.

  2. (optional) If you want to use your OpenBB PAT to access resources, you can set it from the API Keys section (sidebar) in the frontend.

โ Installation ๐Ÿ›ธ
  1. Set up environment variables by creating a .env file in the project directory with the contents specified in .env.template.

  2. [Highly Recommended] Option 1: use the latest Docker image in ghcr.ioโ .

docker run -it -p 8000:8000 --env-file .env ghcr.io/gptstonks/api:main
  • Option 2: build from source.

    1. Install PDMโ  for a faster install.

    2. Clone this repository to your local machine:

    git clone https://github.com/GPTStonks/api.git
    
    1. Navigate to the project directory:
    cd gptstonks_api
    
    1. Install the required dependencies:
    pdm install --no-editable --no-self
    
    1. Create openssl.cnf to allow legacy TLS renegotiation, needed for OECD data in OpenBB.
    echo 'openssl_conf = openssl_init\n\
    \n\
    [openssl_init]\n\
    ssl_conf = ssl_sect\n\
    \n\
    [ssl_sect]\n\
    system_default = system_default_sect\n\
    \n\
    [system_default_sect]\n\
    Options = UnsafeLegacyRenegotiation'\
    > openssl.cnf
    
    1. Start the API:
    uvicorn gptstonks_api.main:app --host 0.0.0.0 --port 8000
    

Now your GPTStonks Financial Chatbot API is up and running!

โ For Production Environments ๐Ÿญ

For production environments, additional steps are necessary to ensure security and stability:

Ensure that uvicorn is configured with SSL certificates for secure HTTPS communication.

Build the Docker image from source:

docker build -t gptstonks-api:v0.1_pro -f Dockerfile.pro .

Now you can run the Docker image with the following command:

docker run -it -p 443:8000 \
-v /etc/letsencrypt/live/api.gptstonks.net/fullchain.pem:/api/cert.pem \
-v /etc/letsencrypt/live/api.gptstonks.net/privkey.pem:/api/key.pem \
--env-file .env gptstonks-api:v0.1_pro

โ Usage๐Ÿ’ก

To use the GPTStonks Financial Chatbot API, send HTTP requests to the provided endpoints. You can interact with the chatbot by sending messages and receiving responses in real-time.

โ API Endpoints๐ŸŒ

Check http://localhost:8000/docs once the API is started to access the endpoints' documentation.

โ Configuration with environment variables โš™๏ธ

Env variableRequiredDefaultDescription
MONGO_URIYes-MongoDB's URI to connect.
MONGO_DBNAMEYes-MongoDB's database to use.
AUTOLLAMAINDEX_VSI_GDRIVE_URINoNone (Not downloaded)Google Drive's URL to download Vector Store Index (VSI).
AUTOLLAMAINDEX_EMBEDDING_MODEL_IDNo"local:BAAI/bge-large-en-v1.5"Embedding model ID to use with AutoLlamaIndex (must match with VSI).
AUTOLLAMAINDEX_SIMILARITY_POSTPROCESSOR_CUTOFFNo0.5Minimum similarity required when retrieving similar documents.
AUTOLLAMAINDEX_REMOVE_METADATA_POSTPROCESSORNoNone (Postprocessor used)Whether or not to use a metadata postprocessor.
AUTOLLAMAINDEX_VSI_PATHYes-Path to the downloaded VSI. If AUTOLLAMAINDEX_VSI_GDRIVE_URI is given, they will match automatically.
AUTOLLAMAINDEX_LLM_CONTEXT_WINDOWNo4096Context window to use when a Hugging Face model is loaded in AutoLlamaIndex.
AUTOLLAMAINDEX_QA_TEMPLATENoNone (LlamaIndex's Default QA Template)Template to use with LlamaIndex question answering step.
AUTOLLAMAINDEX_REFINE_TEMPLATENoNone (LlamaIndex's Default Refine Template)Template to use with AutoLlamaIndex refine step.
AUTOLLAMAINDEX_VIR_SIMILARITY_TOP_KNo3K most similar elements are retrieved with vector search.
AUTOLLAMAINDEX_NOT_USE_HYBRID_RETRIEVERNoNone (Hybrid retrieved used)Whether or not to use BM25 with vector search (hybrid) or only vector search.
AGENT_REQUEST_TIMEOUTNo20No. seconds to wait before timeout when an API LLM is used (e.g., OpenAI).
AGENT_EARLY_STOPPING_METHODNo"generate"How the model should return its final output when early stopping is applied.
LLM_TEMPERATURENo0.1Temperature to use when sampling.
LLM_MAX_TOKENSNo256No. max. tokens to sample.
LLM_TOP_PNo1.0Top-p parameter to apply when sampling.
LLM_MODEL_IDYes-ID of the model to use. See tutorials in GPTStonks' blog for more details.
LLM_CHAT_MODEL_SYSTEM_MESSAGENo"You write concise and complete answers."System message when using chat models (e.g., GPT-4).
LLM_VERTEXAI_CLOUD_LOCATIONNoNoneGoogle Cloud location to use with VertexAI.
LLM_LLAMACPP_CONTEXT_WINDOWNo4000Context window to apply when a model is loaded with Llama.cpp.
LLM_HF_DEVICENo-1Device to use with Hugging Face's models.
LLM_HF_DISABLE_SAMPLINGNoFalseWhether or not to disable sampling when generating with Hugging Face's models.
LLM_HF_DEVICE_MAPNoNone (HuggingFacePipeline default)Device map to use with Hugging Face's models.
LLM_HF_BITSNo4No. bits of quantized Hugging Face's model.
LLM_HF_DISABLE_EXLLAMANoFalseWhether or not to disable ExLlama with Hugging Face's models.
LLM_HF_TRUST_REMOTE_CODENoFalseWhether or not to trust remote code with Hugging Face's models.
OPENBBCHAT_TOOL_DESCRIPTIONYes-OpenBB Platform's tool description for the LLM agent.
SEARCH_TOOL_DESCRIPTIONNoNone (Default DDG Search description)DDG's search tool description for the LLM agent.
CUSTOM_GPTSTONKS_PREFIXNoNone (Default LangChain agent prefix)Prefix to use with LLM agent.
CUSTOM_GPTSTONKS_SUFFIXNoNone (Default LangChain agent suffix)Suffix to use with LLm agent.
CUSTOM_GPTSTONKS_QA (DEPRECATED)NoNone (LlamaIndex's Default QA Template)QA template to use with LLM agent QA tools.

โ Contributing ๐Ÿค

We welcome contributions from the community! If you have any suggestions, bug reports, or want to contribute to the project, feel free to open issues or propose changes.

โ License ๐Ÿ“ƒ

This project is licensed under the MIT License.

Tag summary

Content type

Image

Digest

sha256:71e81e55cโ€ฆ

Size

3.3 GB

Last updated

over 2 years ago

docker pull gptstonks/api