LlamaCPP
class with the appropriate parameters. Here is an example of how to do it:from llama_index.llms.llama_cpp import LlamaCPP model_url = "<https://huggingface.co/TheBloke/Llama-2-13B-chat-GGML/resolve/main/llama-2-13b-chat.ggmlv3.q4_0.bin"> llm = LlamaCPP( # You can pass in the URL to a GGML model to download it automatically model_url=model_url, # optionally, you can set the path to a pre-downloaded model instead of model_url model_path=None, temperature=0.1, max_new_tokens=256, # llama2 has a context window of 4096 tokens, but we set it lower to allow for some wiggle room context_window=3900, # kwargs to pass to __call__() generate_kwargs={}, # kwargs to pass to __init__() # set to at least 1 to use GPU model_kwargs={"n_gpu_layers": 1}, verbose=True, )
model_url
is the URL to the GGML model that will be downloaded automatically. You can replace this with the URL of your OpenAPI compatible LlamaCPP server.OpenAPIToolSpec
and RequestsToolSpec
classes. Here is an example of how to do it:from llama_index.tools.openapi.base import OpenAPIToolSpec from llama_index.tools.requests.base import RequestsToolSpec from llama_index.tools.tool_spec.load_and_search.base import LoadAndSearchToolSpec # Load the OpenAPI spec for your server open_api_spec = ... # Load your OpenAPI spec here open_spec = OpenAPIToolSpec(open_api_spec) requests_spec = RequestsToolSpec( { "your-server-url": { "Authorization": "Bearer your-key", "Content-Type": "application/json", } } ) # OpenAPI spec is too large for content, wrap the tool to separate loading and searching wrapped_tools = LoadAndSearchToolSpec.from_defaults( open_spec.to_tool_list()[0], ).to_tool_list() agent = OpenAIAgent.from_tools( [*wrapped_tools, *requests_spec.to_tool_list()], verbose=True )
"your-server-url"
with the URL of your OpenAPI compatible server and "Bearer your-key"
with the appropriate authorization for your server.OpenAILike
class in LlamaIndex is designed to be a thin wrapper around the OpenAI model, making it compatible with 3rd party tools that provide an OpenAI-compatible API. If you're getting a validation error, it might be due to incorrect setup or usage.OpenAILike
:from llama_index.llms.openai_like import OpenAILike llm = OpenAILike(model="my model", api_base="<http://localhost:port",> api_key="fake") response = llm.complete("Hello World!") print(str(response))
"my model"
with the name of your model, "<http://localhost:port"
> with your local host IP and port, and "fake"
with your API key if required.api_base
.BaseComponent
class in a context where a BaseComponent
subclass is expected.QueryComponent
, BaseLLMComponent
, LLMChatComponent
, CustomLLM
, and others inherit from BaseComponent
. These classes have specific methods and properties that LlamaIndex expects to be present when working with components.BaseComponent
or one of its subclasses. Here's a basic example of how to create a custom component:from llama_index.core.base.query_pipeline.query import BaseComponent class MyCustomComponent(BaseComponent): # Your custom code here pass