Giter Club home page Giter Club logo

claude-api's Introduction

ClaudeAI for Node.js/GoLang

Slack Conversation Library for ClaudeAI.

Web Conversation Library for ClaudeAI. link

Service For SillyTavern

Usage

go get github.com/bincooo/claude-api@[commit]

使用slack for claude

const (
    token = "xoxp-xxx"
    botId = "U05382WAQ1M"
)
options := claude.NewDefaultOptions(token, botId, vars.Model4Slack)
chat, err := claude.New(options)
if err != nil {
    panic(err)
}

// 如果不手建频道,默认使用chat-9527
if err := chat.NewChannel("chat-7890"); err != nil {
    panic(err)
}

prompt := "hi"
fmt.Println("You: ", prompt)
// 不支持附件
partialResponse, err := chat.Reply(context.Background(), prompt, nil)
if err != nil {
    panic(err)
}
Println(partialResponse)

// ======

func Println(partialResponse chan types.PartialResponse) {
	for {
		message, ok := <-partialResponse
		if !ok {
			return
		}

		if message.Error != nil {
			panic(message.Error)
		}

		fmt.Println(message.Text)
		fmt.Println("===============")
	}
}

使用web for claude

var (
    token = "sk-ant-xxx"
    attrCtx = "==附件内容=="
)

// 可自动获取token,无需手动注册
tk, err := util.Login("http://127.0.0.1:7890")
if err != nil {
    panic(err)
}
token = tk
options := claude.NewDefaultOptions(token, "", vars.Model4WebClaude2)
options.Agency = "http://127.0.0.1:7890"
chat, err := claude.New(options)
if err != nil {
    panic(err)
}

prompt := "who are you?"
fmt.Println("You: ", prompt)
// 正常对话
partialResponse, err = chat.Reply(context.Background(), prompt, nil)
if err != nil {
    panic(err)
}
Println(partialResponse)
// 附件上传
prompt = "总结附件内容:"
fmt.Println("You: ", prompt)
ctx, cancel := context.WithTimeout(context.TODO(), time.Second*20)
defer cancel()
partialResponse, err = chat.Reply(ctx, prompt, []types.Attachment{
    {
        Content:  attrCtx,
        FileName: "paste.txt",
        FileSize: 999999,
        FileType: "txt",
    }
})
if err != nil {
    panic(err)
}
Println(partialResponse)

// =========

func Println(partialResponse chan types.PartialResponse) {
	for {
		message, ok := <-partialResponse
		if !ok {
			return
		}

		if message.Error != nil {
			panic(message.Error)
		}

		fmt.Println(message.Text)
		fmt.Println("===============")
	}
}

New 🎉🎉🎉

(2023-09-01)自动刷取token凭证失效,添加临时方案(不保证可用性,也许会抽风) 若无法搭建,可尝试使用claudeai.ai的国内转发(修改.env文件):

# 自行搭建注册接口,或者直接使用claudeai.ai的:https://email.claudeai.ai/claude_api
REV=https://email.claudeai.ai/claude_api

*tips:对电脑要求比较高,吃性能, 手机啥的就不要想了

视频教程

镜像版本请以hub.docker.com上的为准!!点我查看

step 1:

电脑需安装docker,自行研究安装。

安装完成后执行命令,可查看是否安装成功

docker info

step 2:

同级目录下创建.env文件,填写你的电脑ip和vpn (根据个人需要填写,英美地区电脑就不需要填写,留空)。

ip是你本机的ip,不要填写127.0.0.1,不然容器无法识别

PROXY="http://[你电脑的ip]:7890"

step 3:

运行镜像:docker compose和 指令二选一

docker compose

version: '3'
services:
  app:
    restart: always
    image: bincooo/claude-helper:v1.0.2
    volumes:
     - ./.env:/code/.env
    environment:
     - ENABLED_X11VNC=no
    ports:
     - 8088:8080

docker command

docker run --name claude-helper -p 8088:8080 -v ./.env:/code/.env -d bincooo/claude-helper:v1.0.2

(2023-07-28)提供自动刷取token凭证 RECAPTCHA_KEYRECAPTCHA_TOKEN 的值在claude.ai的登陆页面随意填写邮箱,点击发送后在开发者工具中的https://claude.ai/api/auth/send_code 请求中获取

1. 是否有过期时间未知????
2. 是否与IP绑定未知????

(实验性功能)请自行测试研究...

+++++++++++
添加了web新出的claude-2 🎉

食用方法,在浏览器内登陆,打开开发者工具(F12),复制Cookie中的sessionKey即可。

sessionKey便是程序中的token,appid就不需要了,具体使用参考示例:examples/claude-2/main.go

授权以及获取user-token

网页(登录)后, 进入api配置页面(点我跳转)。

〉》点击 【Create an app】

​ 〉》主页看见Your Apps并弹出窗口【Create an app】 〉》 点击【From scratch】

​ 〉》填写app名称以及选择工作空间(例:name: Bot, workspace: chat) 〉》 点击【Create App】

​ 〉》点击左侧边栏上的【OAuth & Permissions】 〉》 下拉至【Scopes】卡片,在 【User Token Scopes】 项下添加权限,如下:

​ channels:history, channels:read, channels:write, groups:history, groups:read, groups:write,

​ chat:write, im:history, im:write, mpim:history, mpim:write

​ 〉》回到顶部【OAuth Tokens for Your Workspace】栏,点击【Install to Workspace】,然后确认授权即可

至此,获得拥有一定权限的user-token

截屏2023-04-18 09.10.56

截屏2023-04-18 09.14.41

获取 claude appid

截屏2023-04-18 08.49.20

注意事项

由于是Slack转接Claude,Slack是有限流机制读我。 目前使用的是web协议对接,文档说明似乎是1秒一个请求,后面可以尝试使用sock对接可拥有更多的请求流量。

Credits Thank you to:

claude-api's People

Contributors

bincooo avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

claude-api's Issues

看起来这个邮箱注册寄了

verify_code Error: 403 Text={"error":{"type":"permission_error","message":"signups_disabled"}}

之前的账号:[Claude2Error::invalid_request_error]Account in read-only mode

import 引入使用会报错

require() of ES Module /app/node_modules/p-timeout/index.js from /app/node_modules/claude-api/build/index.js not supported
请问这个是什么原因?

login出问题了

login出问题了,看了邮箱地址报错,换了其他的,还是有问题,爆权限错误,应该是InnerRk和InnerRT被制裁了

The response information is incomplete

最后一次触发onMessage返回的数据。最后还少了一句话,就不返回数据了。请问是否有遇到这种情况?
环境:把claude-api部署到aws lambda function

{
    "id": "45ac590c-ab7e-4427-8b9f-ce4c83251ad9",
    "text": " 最高的楼一般称为“世界第一高楼”或“世界最高楼”。目前世界最高楼为位于阿拉伯联合酋长国迪拜的哈利法塔,高828米,共163层。\n\n下一步高楼排名前几名为:\n\n2. 上海中心大厦,上海,632米,128层\n\n3. 马来西亚Petronas双子塔,吉隆坡,452米,88层\n\n4. 台北101,台北,508米,101层\n\n5. 广州仪电广场,广州,440米,103层 \n\n除此之外,许多城市都在争相建设新的最高楼,以提高城市知名度和吸引游客。最著名的有:\n\n•土耳其伊斯坦布尔的土耳其最高塔,预计高度将达到约1000米。\n\n•沙特阿拉伯吉达的麦加皇家钟楼,预计高度1001米,将超过哈利法塔。\n\n•美国芝加哥的Willis塔,预计高度直达1450米,如果建成将成为新的世界最高楼。\n\n等等。最高楼的建设一直是各国展示科技实力和城市魅力的重要手段,也成为城市发展和世界各地\n\n",
    "conversation_id": "fd1edaaa-776f-4068-9caa-fb6619012677"
}

slack上可以看到完整的回复

image

advice

大佬牛逼,这个claude-api的go库可以把文档完善更详细一些,写一个go使用claude包使用claude的example。

请问报301是什么原因?

[WARN] web-api:WebClient:0 http request failed An HTTP protocol error occurred: statusCode = 301

[WARN] web-api:WebClient:0 http request failed An HTTP protocol error occurred: statusCode = 301

[WARN] web-api:WebClient:0 http request failed An HTTP protocol error occurred: statusCode = 301

注册不行了

{"error":{"type":"invalid_request_error","message":"recaptcha_failed"}}

上下文对话未生效

const claudeUnofficalChat = async (options,handleMessage) => {
  try{
    const module = await import('claude-api');
    let {token,appid,message,userId,conversationId}=options
    token = decrypt(token)
    appid = decrypt(appid)
    const Authenticator = module.default;
    token = token,
    // claude appid
    bot = appid,
    text = message

  const authenticator = new Authenticator(token, bot)
  // 创建一个频道,已存在则直接返回频道ID
  const channel = await authenticator.newChannel(`chat-${userId}`)
  let isStart=false
  let chatoptions = {
    text, channel, onMessage: (data) => {
      if(!isStart){
        isStart=true
        handleMessage('[START]')
      }
      handleMessage(data.text)
    }
  }
  if(conversationId){
    chatoptions.conversationId=conversationId
  }
  console.log(chatoptions)

  let result = await authenticator.sendMessage(chatoptions)
  handleMessage(`[DONE]${result.conversationId}`)
  console.log('==============1\n', result)
  }catch(error){
   handleMessage(`[ERROR]`)
   throw error
  }
}

你好,想请教下上下文为什么不起作用,我第二次对话时查看了chatoptions配置项传递的conversationId是有值的,且是第一次对话返回的conversationId值,但是并不能实现上下文对话

关于彻底解决注册时报signup_disabled

非常感谢大佬开此坑!

近期是发现用着用着就报账号readonly了,之后重新login报signup_disabled是因为邮箱被拉黑了?
观察了近期几次更新,貌似是从邮箱接码解决的?触发这个原因是因为上面说的邮箱后缀导致的嘛?
感觉可以把接码业务抽象成接口来方便后期无缝或自行实现此项功能?
还有recaptcha的验证码token有没有可能从他们的前端js里抓取?

希望能跟大佬讨论一下这些问题,之后我看一下能不能帮忙一起改进这个过程~

这个的qps是多少呢?

我刚在测试,使用3个频道,然后1分钟发送4千个请求,发现一百多就被频控了。是否可以实现1分钟4千个请求的需求呢?

image

有一些会没有回复
image

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.