Giter Site home page Giter Site logo

aldotai-tg's Introduction

Give me some support🥰

USDT(Ethereum): 0xbef5adf343f46b79d408be6f527a1bec27bdd533

USDT(TRON): TCZazBQV4TtuZutGixN5LM1X1bC9bRy9JK

aldotai-tg's People

Contributors

kaixinol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

aldotai-tg's Issues

[Feature Request] Better error handling

except Exception as e:
return {"msg": str(e), "error": True}

此处可增加判断报错类型,例如:

try:
    pass  # Impl: OpenAI ChatGPT
except openai.error.OpenAIError as e:
    if "maximum context length" in (e := str(e)):
        # Exc: 超出最多 Token 限制
        pass
    return ...

超出最多 Token 限制时可尝试依次 pop() 内存中的对话数据,随后重新发起请求,该情况下一般无需 sleep,可能的 impl 如下:

data_set: dict = {}

def pop_head():
    # 从 data_set 中依次移除对话,保留 {"role": "system"}
    pass

async def chat(*args, **kwargs):
    try:
        pass  # Impl: OpenAI ChatGPT
    except openai.error.OpenAIError as e:
        if "maximum context length" in (e := str(e)):
            pop_head()
            return await chat(*args, **kwargs)
        return ...  # Impl: Handle other errors 

需要注意的是,此处仅为大致思路,实际开发时建议加入 retries 等参数以防止出现过多重试。

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.