gpt_academic icon indicating copy to clipboard operation
gpt_academic copied to clipboard

[Feature]: 是否有支持Gemini等非gpt模型URL重定向的计划?

Open wl223600 opened this issue 1 year ago • 4 comments

Class | 类型

大语言模型

Feature Request | 功能请求

当前版本下GPT_Academic的OPENAI系列模型是可以将指向api.openai.com的url重定向到用户自定义的地址的。然而,目前在wiki内未见到Gemini模型的相关配置参考。如果当前没有此功能支持的话,是否可以考虑后期的某一个版本添加相关支持?

备注: 原有的对Gemini API URL的定义位于request_llms/com_google.py内: def __init__(self): self.url_gemini = "https://generativelanguage.googleapis.com/v1beta/models/%m:streamGenerateContent?key=%k" ~~尽管可以直接对此URL进行编辑,但似乎并不是一种“优雅”的解决办法。~~

另外,在GPT-Academic使用Gemini-Pro模型的相应速度似乎与通过curl直接调用有较大差距。

wl223600 avatar Feb 09 '24 03:02 wl223600

Class | 类型

大语言模型

Feature Request | 功能请求

当前版本下GPT_Academic的OPENAI系列模型是可以将指向api.openai.com的url重定向到用户自定义的地址的。然而,目前在wiki内未见到Gemini模型的相关配置参考。如果当前没有此功能支持的话,是否可以考虑后期的某一个版本添加相关支持?

备注: 原有的对Gemini API URL的定义位于request_llms/com_google.py内: def __init__(self): self.url_gemini = "https://generativelanguage.googleapis.com/v1beta/models/%m:streamGenerateContent?key=%k" ~尽管可以直接对此URL进行编辑,但似乎并不是一种“优雅”的解决办法。~

另外,在GPT-Academic使用Gemini-Pro模型的相应速度似乎与通过curl直接调用有较大差距。

curl调用是非stream的调用

binary-husky avatar Feb 17 '24 06:02 binary-husky

我目前没有方便的代理,请测试这个分支https://github.com/binary-husky/gpt_academic/pull/1560,如果没问题告诉我

binary-husky avatar Feb 17 '24 06:02 binary-husky

emmmm,报了个错。

Traceback (most recent call last):
  File "C:\Users\wl223\AppData\Local\Programs\Python\Python310\lib\site-packages\gradio\routes.py", line 422, in run_predict
    output = await app.get_blocks().process_api(
  File "C:\Users\wl223\AppData\Local\Programs\Python\Python310\lib\site-packages\gradio\blocks.py", line 1323, in process_api
    result = await self.call_function(
  File "C:\Users\wl223\AppData\Local\Programs\Python\Python310\lib\site-packages\gradio\blocks.py", line 1067, in call_function
    prediction = await utils.async_iteration(iterator)
  File "C:\Users\wl223\AppData\Local\Programs\Python\Python310\lib\site-packages\gradio\utils.py", line 336, in async_iteration
    return await iterator.__anext__()
  File "C:\Users\wl223\AppData\Local\Programs\Python\Python310\lib\site-packages\gradio\utils.py", line 329, in __anext__
    return await anyio.to_thread.run_sync(
  File "C:\Users\wl223\AppData\Local\Programs\Python\Python310\lib\site-packages\anyio\to_thread.py", line 56, in run_sync
    return await get_async_backend().run_sync_in_worker_thread(
  File "C:\Users\wl223\AppData\Local\Programs\Python\Python310\lib\site-packages\anyio\_backends\_asyncio.py", line 2134, in run_sync_in_worker_thread
    return await future
  File "C:\Users\wl223\AppData\Local\Programs\Python\Python310\lib\site-packages\anyio\_backends\_asyncio.py", line 851, in run
    result = context.run(func, *args)
  File "C:\Users\wl223\AppData\Local\Programs\Python\Python310\lib\site-packages\gradio\utils.py", line 312, in run_sync_iterator_async
    return next(iterator)
  File "G:\Software\gpt_academic\toolbox.py", line 115, in decorated
    yield from f(txt_passon, llm_kwargs, plugin_kwargs, chatbot_with_cookie, history, system_prompt, *args)
  File "G:\Software\gpt_academic\request_llms\bridge_all.py", line 777, in predict
    yield from method(inputs, llm_kwargs, *args, **kwargs)
  File "G:\Software\gpt_academic\request_llms\bridge_google_gemini.py", line 73, in predict
    genai = GoogleChatInit(llm_kwargs)
  File "G:\Software\gpt_academic\request_llms\com_google.py", line 148, in __init__
    self.url_gemini = endpoint + "/%m:streamGenerateContent?key=%k"
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

~~平时GPT_Academic是放在Debian 12上跑的,奈何报错的排版让人血压升高,就用Windows 11跑了。~~

config_private.py配置节选(另暂时性提供可供临时使用的Gemini API镜像以便测试):

API_URL_REDIRECT = {"https://api.openai.com/v1/chat/completions": "https://api.example.com/v1/chat/completions",
                    "https://generativelanguage.googleapis.com/v1beta/models": "https://api06c297aec697ec9f.easysvc.xyz/v1beta/models"}

~~后来试了一下把上面那个对OpenAI的重定向删了也不行,同样的报错。~~:(

提示:是不是这儿少改了什么东西?None是否应该改为gemini_endpointrequest_llms\bridge_all.py

    "gemini-pro": {
        "fn_with_ui": genai_ui,
        "fn_without_ui": genai_noui,
        "endpoint": None,
        "max_token": 1024 * 32,
        "tokenizer": tokenizer_gpt35,
        "token_cnt": get_token_num_gpt35,
    },
    "gemini-pro-vision": {
        "fn_with_ui": genai_ui,
        "fn_without_ui": genai_noui,
        "endpoint": None,
        "max_token": 1024 * 32,
        "tokenizer": tokenizer_gpt35,
        "token_cnt": get_token_num_gpt35,
    }

另一无关紧要的问题:Gemini系列模型的对话记录无法记录到gpt_log内。~~尝试照葫芦画瓢中。~~ ~~排查了一下生成request本身没啥问题,慢的是收到response,又看不出明显的代码问题。用完全一样的payload去curl手动测试,发现curl生成回复的速度简直飞起。~~

wl223600 avatar Feb 17 '24 13:02 wl223600

"endpoint": None,

修改了一下

https://github.com/binary-husky/gpt_academic/pull/1560

binary-husky avatar Feb 25 '24 13:02 binary-husky

抱歉上几周忙没来的及看,现在似乎可以了。谢谢~

wl223600 avatar Mar 15 '24 12:03 wl223600