langextract icon indicating copy to clipboard operation
langextract copied to clipboard

no support for OpenAI compatible model, with params of base_url, model_id, api_key

Open YunfanGoForIt opened this issue 1 year ago • 4 comments

I want to use AliCloud Modelscope models which is OpenAI compatible model, with params of base_url, model_id, api_key

YunfanGoForIt avatar Aug 06 '25 05:08 YunfanGoForIt

see #53, implemented in #51

mariano avatar Aug 06 '25 11:08 mariano

Hi @YunfanGoForIt,

Good news - PR #51 was just merged, adding base_url support for OpenAI-compatible endpoints. This should enable AliCloud Modelscope and other OpenAI-compatible services.

You can now configure the base_url parameter when using OpenAILanguageModel. Please let us know if you encounter any issues.

Thanks for your patience.

aksg87 avatar Aug 06 '25 23:08 aksg87

How to use it in conjunction with langextrect? Can you give a demo?

827648313 avatar Aug 07 '25 08:08 827648313

Is this live in v1.0.4?

Receiving an error:

InferenceOutputError: Parallel inference error: OpenAI API error: Error code: 401 - {'error': {'message': 'Incorrect API key provided: gsk_SjDf****************************************CC. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}

Trying to use the generic OpenAi client not directly from openai, but for example groq:

result = lx.extract( text_or_documents=input_text, prompt_description=prompt, examples=examples, language_model_type=lx.inference.OpenAILanguageModel, model_id="openai/gpt-oss-120b", language_model_params= {'base_url': 'https://api.groq.com/openai/v1', 'api_key':"gx_xxxC", 'model_id':"openai/gpt-oss-120b"} )

I noticed extract takes in model_url but the language_model_type only receives base_url as a keyword arg, so I am using the language_model_params dict?

If i use the same parameters for a separate client connects fine, so seems like an issue in langextract:

client = OpenAI(api_key='gx_xxxC', base_url='https://api.groq.com/openai/v1')

Thanks!

bjg90 avatar Aug 07 '25 17:08 bjg90