Note: Ensure to add /v1 at the end of openai_api_base,
Python
Copy
from langchain.chat_models import ChatOpenAIllm = ChatOpenAI( openai_api_base="https://aihubmix.com/v1", # Note, add /v1 at the end openai_api_key="sk-3133f******fee269b71d",)res = llm.predict("hello")print(res)
Example code for using LLM to make predictions
The core is actually in setting the key and URL
Methods include:
Setting using environment variables
Passing in variables
Manually setting environment variables
Python
Copy
import osimport requestsimport timeimport jsonimport timefrom langchain.llms import OpenAIAPI_SECRET_KEY = "your key from aihubmix";BASE_URL = "https://aihubmix.com/v1"; #Base URL for aihubmixos.environ["OPENAI_API_KEY"] = API_SECRET_KEYos.environ["OPENAI_API_BASE"] = BASE_URLdef text(): llm = OpenAI(temperature=0.9) text = "What would be a good company name for a company that makes colorful socks?" print(llm(text))if __name__ == '__main__': text();