tmc / langchaingo

LangChain for Go, the easiest way to write LLM-based programs in Go
https://tmc.github.io/langchaingo/
MIT License
3.75k stars 521 forks source link

How to call LLM using custom API? #866

Open wjx-xin opened 1 month ago

wjx-xin commented 1 month ago

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

erictse commented 1 month ago

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

wjx-xin commented 4 weeks ago

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?

erictse commented 4 weeks ago

@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

wjx-xin commented 4 weeks ago

@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