GithubHelp home page GithubHelp logo

xkrfer / claude-in-slack-api Goto Github PK

View Code? Open in Web Editor NEW
14.0 2.0 1.0 373 KB

Convert claude to chatgpt form api through Slack

License: MIT License

JavaScript 3.76% Dockerfile 9.79% TypeScript 83.13% Shell 3.31%
chatgpt-api claude-api

claude-in-slack-api's Introduction

claude-in-slack-api

Convert claude to chatgpt form api through Slack

Conversion Details

Use the Slack API to send messages to Claude and receive his replies through the Slack API. Then, format the replies in the format of the chatgpt interface and return them to the user, allowing Claude to be used on any platform that supports the chatgpt API.

How to use

1. GET Slack User Token and Bot ID

Claude|媲美ChatGPT,如何免费接入到个人服务

2. Run

  1. Create a "config" directory in the current directory and add an ".env" file, then fill it with the following content:

    # .env
    CLAUDE_BOT_ID=your_CLAUDE_BOT_ID
    SLACK_USER_TOKEN=your_SLACK_USER_TOKEN
    TOKEN=your_TOKEN # any string you like
    SPLIT_STREAM=true # whether to split the stream, if false will return all the results at once, default true
  2. Run

    docker run -p 9000:9000 \
         -d --restart=always \
         --volume ./config:/config \
         --name claude-api \
         xkrfer/claude-in-slack-api
  3. Test

    curl --location 'http://127.0.0.1:9000/v1/chat/completions' \
      --header 'Content-Type: application/json' \
      --header 'Authorization: Bearer token' \
      --data '{
      "model": "gpt-3.5-turbo",
      "messages": [
         {
         "role": "user",
         "content": "hello"
         }
      ],
      "max_tokens": 100,
      "temperature": 1,
      "stream": true
    }'
  4. If you need to reverse proxy using Nginx, you will need to add the following content to your Nginx configuration file:

    location /
    {
        proxy_pass http://127.0.0.1:9000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
        # support sse
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        chunked_transfer_encoding off;
        proxy_buffering off;
        proxy_cache off;
        proxy_redirect off;
        proxy_hide_header Cache-Control;
    }
    
  5. Open https://web.chatboxapp.xyz and enter the address of your server, then you can chat with Claude. img

Pay attention to

Convert this service to HTTPS in order to avoid potential errors that may arise on other tools.

Thanks

yokonsan/claude-in-slack-api
jtsang4/claude-to-chatgpt
Bin-Huang/chatbox 如何通过Dockerfile优化Nestjs镜像大小

claude-in-slack-api's People

Contributors

xkrfer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

arvintian

claude-in-slack-api's Issues

添加 Claude /reset 命令执行接口 slack chat.command

//app.controller.ts
  @Get('/claude/reset')
  @HttpCode(200)
  async claude_reset(@Res() res: Response) {
    const response = await this.appService.reset();
    return res.json(response);
  }

//app.service.ts
  async reset() {
    return await this.slackClient.reset()
  }


//slack.client.ts
  async reset(): Promise<string> {
    const formdata = new FormData();
    formdata.append("token", process.env.SLACK_CLAUDE_TOKEN);
    formdata.append("channel", process.env.SLACK_CLAUDE_CHANNEL);
    formdata.append("command", "/reset");

    try {
      const api = await fetch('https://jydhq.slack.com/api/chat.command', {
        headers: {
          'Cookie': process.env.SLACK_COOKIE
        },
        body: formdata,
        method: 'post'
      })

      return await api.json()
    } catch (error) {
      console.error('Error execute reset command:', error);
      return JSON.stringify({ 'ok': false, 'error': error.message })
    }
  }

yokonsan/claude-in-slack-api#7 (comment)

请问如何让回复的文本保存在同一个响应里

3
4
比如这样一句分了4段,我在一些项目里测试时发现,如果长句子被分的太多会导致最前面的数据丢失。
请问这种情况该如何解决
我在逛b站时倒是看到一个作者的类似项目,他的那个只能等Claude加载完成后,一次性获取完整的一段文本而不是一点一点加载的。
但我不知道该如何实现

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.