Giter VIP home page Giter VIP logo

tj31moll / aitelegramchatbot Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 278 KB

This repository contains a Python script for a Telegram bot that integrates with OpenAI's API or other compatible REST APIs (such as Jan https://jan.ai/). It's designed to provide an interactive AI experience through Telegram, using simple chat functionalities.

Python 100.00%
api-rest chatbot gpt mistral openai phi-2 telegram telegram-bot

aitelegramchatbot's Introduction

AItelegramchatbot

Screenshot

This repository contains a Python script for a Telegram bot that integrates with OpenAI's API or other compatible REST APIs (such as Jan https://jan.ai/). It's designed to provide an interactive AI experience through Telegram, using simple chat functionalities.

Features

  • Easy Interaction: Users can interact with the bot using a /chat command followed by their message.
  • Flexible API Integration: Compatible with OpenAI and similar REST APIs.
  • Customizable Responses: The bot can be configured to modify its behavior, response tone, and other settings.

Getting Started

Prerequisites

  • Python 3.x
  • python-telegram-bot library
  • OpenAI API or a compatible API

Installation

  1. Clone the repository:

    git clone https://github.com/tj31moll/AItelegramchatbot
  2. Install the required packages:

    pip install -r requirements.txt
  3. Set up your OpenAI API key and Telegram Bot Token in the script.

Usage

Run the script:

python bot.py

Configuration

  • Bot Token: Replace your-bot-token in the script with your actual Telegram Bot Token.
  • API Key: Set up your OpenAI API key or the key for an alternative API.
  • Allowed Chat IDs: Define the chat IDs that are allowed to interact with the bot for security.
  • System Prompt: Adding a System PromptSystem Prompt Configuration: To customize the behavior of your bot, you can add a system prompt. This prompt acts as an initial input to the AI model, influencing how the bot responds to user messages.To add a system prompt, locate the section in the script where the chat function is defined.Add a variable to hold your prompt, like system_prompt = "Your system prompt here".When creating the completion request to the OpenAI API, include the system_prompt as part of the input. For example:
    completion = client.chat.completions.create(
    model="local-model",
    messages=[
        {"role": "system", "content": system_prompt},
        {"role": "user", "content": user_message}
    ],
    temperature=0.7,)
  • This system prompt can include instructions or a specific tone/style you want the bot to follow, setting the context for its responses.ExampleHere's an example of setting a system prompt that instructs the bot to be friendly and informative:system_prompt = "Be friendly and informative in your responses."Remember, the system prompt is a powerful tool to guide the interaction flow and style of your bot. Feel free to experiment with different prompts to see how they affect the bot's behavior.
  • Note that only certain transfomrers allow system prompts. I have tested this with the Phi-2 model and transformer.

Contributing

Contributions, issues, and feature requests are welcomed!

License

Distributed under the MIT License. See LICENSE for more information.

Acknowledgements

Jan builds on top of other open-source projects: License - Jan is free and open source, under the AGPLv3 license. OpenAI Python and libraries

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.