Giter Site home page Giter Site logo

deepseek-api's Introduction

Deepseek coder Reverse Engineered API Wrapper

Unofficial API Wrapper for Deepseek (chat.deepseek.com) in Python. This is a reverse-engineered API for the Deepseek coder and Deepseek code chatbots. This API is not affiliated with Deepseek in any way.

Installation

pip install git+https://github.com/rabilrbl/deepseek-api.git

Usage

Asynchronous CLI Example

import asyncio
import os
from deepseek_api import DeepseekAPI
from dotenv import load_dotenv

load_dotenv()


async def main():
    email = os.environ.get("DEEPSEEK_EMAIL")
    password = os.environ.get("DEEPSEEK_PASSWORD")

    async with DeepseekAPI(
        email=email,
        password=password,
        save_login=True,  # save login credentials to login.json
        model_class="deepseek_code",  # Choose from "deepseek_chat" or "deepseek_code"
    ) as app:
        print(
            """
            Usage:
                - Type 'new' to start a new chat.
                - Type 'exit' to exit.
                
            Start chatting!
        """
        )

        while True:
            message = input("> ")

            if message == "exit":
                break
            elif message == "new":
                await app.new_chat()
                continue

            async for chunk in app.chat(message):
                try:
                    # keep printing in one line
                    print(chunk["choices"][0]["delta"]["content"], end="")
                except KeyError as ke:
                    print(ke)
            print()


if __name__ == "__main__":
    asyncio.run(main())

Synchonous CLI Example

import os
from deepseek_api import SyncDeepseekAPI
from dotenv import load_dotenv

load_dotenv()


def main():
    email = os.environ.get("DEEPSEEK_EMAIL")
    password = os.environ.get("DEEPSEEK_PASSWORD")

    app = SyncDeepseekAPI(
        email=email,
        password=password,
        save_login=True,  # save login credentials to login.json
        model_class="deepseek_code",  # Choose from "deepseek_chat" or "deepseek_code"
    )

    print(
        """
          Usage:
            - Type 'new' to start a new chat.
            - Type 'exit' to exit.
            
          Start chatting!
    """
    )

    while True:
        message = input("> ")

        if message == "exit":
            # close the app
            app.close()
            break
        elif message == "new":
            app.new_chat()
            continue

        response = app.chat(message)

        for chunk in response:
            try:
                # keep printing in one line
                print(chunk["choices"][0]["delta"]["content"], end="")
            except KeyError as ke:
                print(ke)
        print()


if __name__ == "__main__":
    main()

License

CC BY-NC-SA 4.0

Disclaimer

This project is not affiliated with Deepseek in any way. Use at your own risk. This project was created for educational purposes only.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

deepseek-api's People

Contributors

rabilrbl avatar

Watchers

 avatar

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.