langchaingo icon indicating copy to clipboard operation
langchaingo copied to clipboard

How to call LLM using custom API?

Open wjx-xin opened this issue 1 year ago • 4 comments

Many llms do not provide calling methods implemented in libraries such as openapi, so how can I implement custom calls?

wjx-xin avatar Jun 02 '24 19:06 wjx-xin

Could elaborate on what you want to do with custom calls and which LLM you want to use?

erictse avatar Jun 03 '24 05:06 erictse

Could elaborate on what you want to do with custom calls and which LLM you want to use?

LLM company provides their own web API, and I want to call it through langchaingo. It seems to be mentioned in langchain (Python) that it can be implemented by inheriting LLM class. Is there a similar implementation in langchaingo?

wjx-xin avatar Jun 03 '24 15:06 wjx-xin

@wjx-xin Yes, except instead of inheritance, you would implement this interface: https://github.com/tmc/langchaingo/blob/main/llms/llms.go#L15-L29

For example, the OpenAI client implementation of that interface: https://github.com/tmc/langchaingo/blob/main/llms/openai/openaillm.go#L47

erictse avatar Jun 04 '24 00:06 erictse

@wjx-xin Yes, except instead of inheritance, you would implement this interface: https://github.com/tmc/langchaingo/blob/main/llms/llms.go#L15-L29

For example, the OpenAI client implementation of that interface: https://github.com/tmc/langchaingo/blob/main/llms/openai/openaillm.go#L47

Thank you. @erictse

wjx-xin avatar Jun 05 '24 00:06 wjx-xin