id
int64
0
190k
prompt
stringlengths
21
13.4M
docstring
stringlengths
1
12k
36,512
from typing import Any, Dict, List, Optional from llama_index.core import Document, ServiceContext, VectorStoreIndex from llama_index.core.llama_pack.base import BaseLlamaPack from llama_index.core.llms.llm import LLM from llama_index.core.node_parser import SentenceSplitter from llama_index.core.query_pipeline.compone...
Apply reciprocal rank fusion. The original paper uses k=60 for best results: https://plg.uwaterloo.ca/~gvcormac/cormacksigir09-rrf.pdf
36,513
from llama_index.cli.rag import RagCLI from llama_index.core.ingestion import IngestionPipeline, IngestionCache from llama_index.core.query_pipeline.query import QueryPipeline from llama_index.core.storage.docstore import SimpleDocumentStore from llama_index.core.text_splitter import SentenceSplitter from llama_index.e...
Init local RAG CLI.
36,514
import asyncio from abc import abstractmethod from copy import deepcopy from typing import Any, Awaitable, Callable, Dict, List, Optional from llama_index.core.bridge.pydantic import BaseModel, Field, PrivateAttr from llama_index.core.utils import get_tqdm_iterable The provided code snippet includes necessary dependen...
Generate parameter combinations.
36,515
import time from functools import partial from typing import Callable, List, Optional, Tuple import pandas as pd from llama_index.core import SimpleDirectoryReader from llama_index.core.base.embeddings.base import ( DEFAULT_EMBED_BATCH_SIZE, BaseEmbedding, ) from llama_index.embeddings import OpenAIEmbedding, r...
null
36,516
import time from functools import partial from typing import Callable, List, Optional, Tuple import pandas as pd from llama_index.core import SimpleDirectoryReader from llama_index.core.base.embeddings.base import ( DEFAULT_EMBED_BATCH_SIZE, BaseEmbedding, ) from llama_index.embeddings import OpenAIEmbedding, r...
null
36,517
import time from functools import partial from typing import Callable, List, Optional, Tuple import pandas as pd from llama_index.core import SimpleDirectoryReader from llama_index.core.base.embeddings.base import ( DEFAULT_EMBED_BATCH_SIZE, BaseEmbedding, ) from llama_index.embeddings import OpenAIEmbedding, r...
Benchmark embeddings.
36,518
import json import os from typing import Dict, Tuple from llama_index import LLMPredictor, SQLDatabase from llama_index.indices import SQLStructStoreIndex from llama_index.llms.openai import OpenAI from sqlalchemy import create_engine, text The provided code snippet includes necessary dependencies for implementing the...
Load examples.
36,519
import json import os from typing import Dict, Tuple from llama_index import LLMPredictor, SQLDatabase from llama_index.indices import SQLStructStoreIndex from llama_index.llms.openai import OpenAI from sqlalchemy import create_engine, text The provided code snippet includes necessary dependencies for implementing the...
Create indexes for all databases.
36,520
import argparse import json import logging import os import re from typing import Any, cast from llama_index import LLMPredictor, SQLDatabase from llama_index.indices import SQLStructStoreIndex from llama_index.llms.openai import OpenAI from sqlalchemy import create_engine, text from tqdm import tqdm def _generate_sql(...
Generate SQL queries for the given examples and write them to the output file.
36,521
import argparse import ast import json import logging import os from typing import Dict, List, Optional from llama_index.core.base.llms.types import ChatMessage, MessageRole from llama_index.core.base.response.schema import Response from llama_index.indices.struct_store.sql import SQLQueryMode, SQLStructStoreIndex from...
null
36,522
import argparse import ast import json import logging import os from typing import Dict, List, Optional from llama_index.core.base.llms.types import ChatMessage, MessageRole from llama_index.core.base.response.schema import Response from llama_index.indices.struct_store.sql import SQLQueryMode, SQLStructStoreIndex from...
null
36,523
from typing import Callable, Dict from llama_index.tools.function_tool import FunctionTool from task import Task The provided code snippet includes necessary dependencies for implementing the `search_number` function. Write a Python function `def search_number(first_name: str, last_name: str) -> str` to solve the foll...
Search for a person by first and last name.
36,524
from typing import Callable, Dict from llama_index.tools.function_tool import FunctionTool from task import Task class Phone: def __init__(self) -> None: self.number = "" self.entered = False def dial_digit(self, number: str) -> None: """Dial a digit on the phone.""" assert len(...
null
36,525
from typing import Callable, Dict from llama_index.tools.function_tool import FunctionTool from task import Task class Phone: def __init__(self) -> None: self.number = "" self.entered = False def dial_digit(self, number: str) -> None: """Dial a digit on the phone.""" assert len(...
null
36,526
from typing import List, cast import pandas as pd from agent_utils import AGENTS, ALL_MODELS, get_model, is_valid_combination from button_tasks import TASKS as BUTTON_TASKS from fire import Fire from llama_index.agent.types import BaseAgent from math_tasks import TASKS as MATH_TASKS ALL_TASKS = list(MATH_TASKS.keys()) ...
null
36,527
The provided code snippet includes necessary dependencies for implementing the `contains_expected_response` function. Write a Python function `def contains_expected_response(response: str, expected_response: str) -> bool` to solve the following problem: Check if the response contains the expected response. Here is t...
Check if the response contains the expected response.
36,528
from typing import Callable, Dict from eval import contains_expected_response from llama_index.tools.function_tool import FunctionTool from task import Task The provided code snippet includes necessary dependencies for implementing the `add` function. Write a Python function `def add(a: int, b: int) -> int` to solve t...
Add two integers and returns the result integer.
36,529
from typing import Callable, Dict from eval import contains_expected_response from llama_index.tools.function_tool import FunctionTool from task import Task The provided code snippet includes necessary dependencies for implementing the `multiply` function. Write a Python function `def multiply(a: int, b: int) -> int` ...
Multiple two integers and returns the result integer.
36,530
import random import time from typing import List from llama_index.schema import TextNode from llama_index.vector_stores.simple import SimpleVectorStore from llama_index.vector_stores.types import ( VectorStoreQuery, VectorStoreQueryMode, ) def generate_nodes( num_vectors: int = 100, embedding_length: int =...
Benchmark simple vector store.
36,531
import re from dataclasses import dataclass from typing import List, Optional from llama_index.core import VectorStoreIndex, get_tokenizer from llama_index.core.llms import ChatMessage from llama_index.core.llms.llm import LLM from llama_index.core.node_parser import TokenTextSplitter from llama_index.core.schema impor...
null
36,532
import re from dataclasses import dataclass from typing import List, Optional from llama_index.core import VectorStoreIndex, get_tokenizer from llama_index.core.llms import ChatMessage from llama_index.core.llms.llm import LLM from llama_index.core.node_parser import TokenTextSplitter from llama_index.core.schema impor...
null
36,533
import random from typing import Any, List, Optional, Tuple from llama_index.core.bridge.pydantic import BaseModel from llama_index.core.indices.query.embedding_utils import get_top_k_embeddings from llama_index.finetuning import EmbeddingQAFinetuneDataset class CohereRerankerFinetuneDataset(BaseModel): def to_jso...
null
36,534
from pathlib import Path from typing import Any, Callable, Dict, List, Optional, Type import torch import transformers from llama_index.core.utils import print_text from llama_index.embeddings.adapter import BaseAdapter from sentence_transformers.util import cos_sim from torch import Tensor, nn from torch.optim import ...
Train model.
36,536
from typing import Any, Dict, Optional, Sequence from llama_index.legacy.objects.base_node_mapping import ( DEFAULT_PERSIST_DIR, DEFAULT_PERSIST_FNAME, BaseObjectNodeMapping, ) from llama_index.legacy.schema import BaseNode, TextNode from llama_index.legacy.tools.query_engine import QueryEngineTool from lla...
Function convert Tool to node.
36,537
import asyncio from abc import abstractmethod from copy import deepcopy from typing import Any, Awaitable, Callable, Dict, List, Optional from llama_index.legacy.bridge.pydantic import BaseModel, Field, PrivateAttr from llama_index.legacy.utils import get_tqdm_iterable The provided code snippet includes necessary depe...
Generate parameter combinations.
36,538
from deprecated import deprecated from llama_index.legacy.output_parsers.base import ChainableOutputParser from copy import deepcopy from typing import TYPE_CHECKING, Any, Callable, Optional The provided code snippet includes necessary dependencies for implementing the `get_callable` function. Write a Python function ...
Get callable.
36,539
import json from dataclasses import dataclass from typing import Any, List from dataclasses_json import DataClassJsonMixin from llama_index.legacy.output_parsers.base import ( OutputParserException, StructuredOutput, ) from llama_index.legacy.output_parsers.utils import _marshal_llm_to_json from llama_index.leg...
null
36,543
import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Type from openai.resources import Completions from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, wait_exponential, ) from llama_index.legacy.bridge.pydantic import BaseModel fro...
Use tenacity to retry the completion call.
36,544
import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Type from openai.resources import Completions from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, wait_exponential, ) from llama_index.legacy.bridge.pydantic import BaseModel fro...
Use tenacity to retry the async completion call.
36,545
import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Type from openai.resources import Completions from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, wait_exponential, ) from llama_index.legacy.bridge.pydantic import BaseModel fro...
Calculate the maximum number of tokens possible to generate for a model. Args: modelname: The modelname we want to know the context size for. Returns: The maximum context size Example: .. code-block:: python max_tokens = openai.modelname_to_contextsize("text-davinci-003") Modified from: https://github.com/hwchase17/lan...
36,546
import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Type from openai.resources import Completions from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, wait_exponential, ) from llama_index.legacy.bridge.pydantic import BaseModel fro...
null
36,547
import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Type from openai.resources import Completions from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, wait_exponential, ) from llama_index.legacy.bridge.pydantic import BaseModel fro...
null
36,548
import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Type from openai.resources import Completions from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, wait_exponential, ) from llama_index.legacy.bridge.pydantic import BaseModel fro...
Convert generic messages to OpenAI message dicts.
36,549
import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Type from openai.resources import Completions from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, wait_exponential, ) from llama_index.legacy.bridge.pydantic import BaseModel fro...
Convert litellm.utils.Message instance to generic message.
36,550
import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Type from openai.resources import Completions from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, wait_exponential, ) from llama_index.legacy.bridge.pydantic import BaseModel fro...
Convert openai message dicts to generic messages.
36,551
import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Type from openai.resources import Completions from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, wait_exponential, ) from llama_index.legacy.bridge.pydantic import BaseModel fro...
Convert pydantic class to OpenAI function.
36,552
import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Type from openai.resources import Completions from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, wait_exponential, ) from llama_index.legacy.bridge.pydantic import BaseModel fro...
null
36,553
import logging from typing import Any, Callable, Optional from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, wait_exponential, ) from llama_index.legacy.core.llms.types import ChatMessage, MessageRole def _create_retry_decorator(max_retries: int) -> Callable...
Use tenacity to retry the completion call.
36,554
import logging from typing import Any, Callable, Optional from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, wait_exponential, ) from llama_index.legacy.core.llms.types import ChatMessage, MessageRole def _create_retry_decorator(max_retries: int) -> Callable...
Use tenacity to retry the completion call.
36,555
import logging from typing import Any, Callable, Optional from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, wait_exponential, ) from llama_index.legacy.core.llms.types import ChatMessage, MessageRole The provided code snippet includes necessary dependencie...
Init vertexai. Args: project: The default GCP project to use when making Vertex API calls. location: The default location to use when making API calls. credentials: The default custom credentials to use when making API calls. If not provided credentials will be ascertained from the environment. Raises: ImportError: If ...
36,556
import logging from typing import Any, Callable, Optional from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, wait_exponential, ) from llama_index.legacy.core.llms.types import ChatMessage, MessageRole class ChatMessage(BaseModel): """Chat message.""" ...
null
36,557
import logging from typing import Any, Callable, Optional from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, wait_exponential, ) from llama_index.legacy.core.llms.types import ChatMessage, MessageRole class MessageRole(str, Enum): """Message role.""" ...
Parse a sequence of messages into history. Args: history: The list of messages to re-create the history of the chat. Returns: A parsed chat history. Raises: ValueError: If a sequence of message has a SystemMessage not at the first place.
36,558
import logging from typing import Any, Callable, Optional from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, wait_exponential, ) from llama_index.legacy.core.llms.types import ChatMessage, MessageRole class MessageRole(str, Enum): """Message role.""" ...
null
36,561
from typing import TYPE_CHECKING, Optional, Union from llama_index.legacy.llms.llama_cpp import LlamaCPP from llama_index.legacy.llms.llama_utils import completion_to_prompt, messages_to_prompt from llama_index.legacy.llms.llm import LLM from llama_index.legacy.llms.mock import MockLLM from llama_index.legacy.llms.open...
Resolve LLM from string or LLM instance.
36,562
import logging from abc import ABC, abstractmethod from typing import Any, Callable, Optional, Sequence from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, wait_exponential, ) from llama_index.legacy.core.llms.types import ChatMessage from llama_index.legacy....
null
36,563
import logging from abc import ABC, abstractmethod from typing import Any, Callable, Optional, Sequence from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, wait_exponential, ) from llama_index.legacy.core.llms.types import ChatMessage from llama_index.legacy....
null
36,564
import logging from abc import ABC, abstractmethod from typing import Any, Callable, Optional, Sequence from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, wait_exponential, ) from llama_index.legacy.core.llms.types import ChatMessage from llama_index.legacy....
Use tenacity to retry the completion call.
36,565
from collections import ChainMap from typing import ( Any, Dict, List, Optional, Protocol, Sequence, get_args, runtime_checkable, ) from llama_index.legacy.bridge.pydantic import BaseModel, Field, validator from llama_index.legacy.callbacks import CBEventType, EventPayload from llama_ind...
Convert a stream completion response to a stream of tokens.
36,566
from collections import ChainMap from typing import ( Any, Dict, List, Optional, Protocol, Sequence, get_args, runtime_checkable, ) from llama_index.legacy.bridge.pydantic import BaseModel, Field, validator from llama_index.legacy.callbacks import CBEventType, EventPayload from llama_ind...
Convert a stream completion response to a stream of tokens.
36,567
from collections import ChainMap from typing import ( Any, Dict, List, Optional, Protocol, Sequence, get_args, runtime_checkable, ) from llama_index.legacy.bridge.pydantic import BaseModel, Field, validator from llama_index.legacy.callbacks import CBEventType, EventPayload from llama_ind...
Convert a stream completion response to a stream of tokens.
36,568
from collections import ChainMap from typing import ( Any, Dict, List, Optional, Protocol, Sequence, get_args, runtime_checkable, ) from llama_index.legacy.bridge.pydantic import BaseModel, Field, validator from llama_index.legacy.callbacks import CBEventType, EventPayload from llama_ind...
Convert a stream completion response to a stream of tokens.
36,569
from collections import ChainMap from typing import ( Any, Dict, List, Optional, Protocol, Sequence, get_args, runtime_checkable, ) from llama_index.legacy.bridge.pydantic import BaseModel, Field, validator from llama_index.legacy.callbacks import CBEventType, EventPayload from llama_ind...
null
36,570
import logging from typing import Any, Callable, Dict, List, Optional, Sequence from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, wait_exponential, ) from llama_index.legacy.core.llms.types import ChatMessage def _create_retry_decorator(max_retries: int) ->...
Use tenacity to retry the completion call.
36,571
import logging from typing import Any, Callable, Dict, List, Optional, Sequence from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, wait_exponential, ) from llama_index.legacy.core.llms.types import ChatMessage def _create_retry_decorator(max_retries: int) ->...
Use tenacity to retry the async completion call.
36,572
import logging from typing import Any, Callable, Dict, List, Optional, Sequence from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, wait_exponential, ) from llama_index.legacy.core.llms.types import ChatMessage ALL_AVAILABLE_MODELS = {**COMMAND_MODELS, **GENE...
null
36,573
import logging from typing import Any, Callable, Dict, List, Optional, Sequence from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, wait_exponential, ) from llama_index.legacy.core.llms.types import ChatMessage COMMAND_MODELS = { "command": 4096, "com...
null
36,574
import logging from typing import Any, Callable, Dict, List, Optional, Sequence from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, wait_exponential, ) from llama_index.legacy.core.llms.types import ChatMessage class ChatMessage(BaseModel): def __str__(...
null
36,578
from typing import Optional from typing_extensions import NotRequired, TypedDict from llama_index.legacy.core.llms.types import ChatMessage class ChatCompletionMessage(TypedDict): role: str content: Optional[str] user: NotRequired[str] class ChatMessage(BaseModel): """Chat message.""" role: Messag...
null
36,579
from typing import Optional from typing_extensions import NotRequired, TypedDict from llama_index.legacy.core.llms.types import ChatMessage XINFERENCE_MODEL_SIZES = { "baichuan": 2048, "baichuan-chat": 2048, "wizardlm-v1.0": 2048, "vicuna-v1.3": 2048, "orca": 2048, "chatglm": 2048, "chatglm2...
null
36,581
from typing import Dict, Type from llama_index.legacy.llms.bedrock import Bedrock from llama_index.legacy.llms.custom import CustomLLM from llama_index.legacy.llms.gradient import ( GradientBaseModelLLM, GradientModelAdapterLLM, ) from llama_index.legacy.llms.huggingface import HuggingFaceLLM from llama_index.l...
Load LLM by name.
36,582
import os from typing import Any, Awaitable, Callable, List, Optional, Sequence from llama_index.legacy.core.llms.types import ( ChatMessage, ChatResponse, ChatResponseAsyncGen, ChatResponseGen, CompletionResponse, CompletionResponseAsyncGen, CompletionResponseGen, MessageRole, ) class ...
Convert messages to a history string.
36,583
import os from typing import Any, Awaitable, Callable, List, Optional, Sequence from llama_index.legacy.core.llms.types import ( ChatMessage, ChatResponse, ChatResponseAsyncGen, ChatResponseGen, CompletionResponse, CompletionResponseAsyncGen, CompletionResponseGen, MessageRole, ) def mes...
Convert a completion function to a chat function.
36,584
import os from typing import Any, Awaitable, Callable, List, Optional, Sequence from llama_index.legacy.core.llms.types import ( ChatMessage, ChatResponse, ChatResponseAsyncGen, ChatResponseGen, CompletionResponse, CompletionResponseAsyncGen, CompletionResponseGen, MessageRole, ) def mes...
Convert a completion function to a chat function.
36,585
import os from typing import Any, Awaitable, Callable, List, Optional, Sequence from llama_index.legacy.core.llms.types import ( ChatMessage, ChatResponse, ChatResponseAsyncGen, ChatResponseGen, CompletionResponse, CompletionResponseAsyncGen, CompletionResponseGen, MessageRole, ) def pro...
Convert a chat function to a completion function.
36,586
import os from typing import Any, Awaitable, Callable, List, Optional, Sequence from llama_index.legacy.core.llms.types import ( ChatMessage, ChatResponse, ChatResponseAsyncGen, ChatResponseGen, CompletionResponse, CompletionResponseAsyncGen, CompletionResponseGen, MessageRole, ) def pro...
Convert a chat function to a completion function.
36,587
import os from typing import Any, Awaitable, Callable, List, Optional, Sequence from llama_index.legacy.core.llms.types import ( ChatMessage, ChatResponse, ChatResponseAsyncGen, ChatResponseGen, CompletionResponse, CompletionResponseAsyncGen, CompletionResponseGen, MessageRole, ) def mes...
Convert a completion function to a chat function.
36,588
import os from typing import Any, Awaitable, Callable, List, Optional, Sequence from llama_index.legacy.core.llms.types import ( ChatMessage, ChatResponse, ChatResponseAsyncGen, ChatResponseGen, CompletionResponse, CompletionResponseAsyncGen, CompletionResponseGen, MessageRole, ) def pro...
Convert a chat function to a completion function.
36,589
import os from typing import Any, Awaitable, Callable, List, Optional, Sequence from llama_index.legacy.core.llms.types import ( ChatMessage, ChatResponse, ChatResponseAsyncGen, ChatResponseGen, CompletionResponse, CompletionResponseAsyncGen, CompletionResponseGen, MessageRole, ) def mes...
Convert a completion function to a chat function.
36,590
import os from typing import Any, Awaitable, Callable, List, Optional, Sequence from llama_index.legacy.core.llms.types import ( ChatMessage, ChatResponse, ChatResponseAsyncGen, ChatResponseGen, CompletionResponse, CompletionResponseAsyncGen, CompletionResponseGen, MessageRole, ) def pro...
Convert a chat function to a completion function.
36,591
import os from typing import Any, Awaitable, Callable, List, Optional, Sequence from llama_index.legacy.core.llms.types import ( ChatMessage, ChatResponse, ChatResponseAsyncGen, ChatResponseGen, CompletionResponse, CompletionResponseAsyncGen, CompletionResponseGen, MessageRole, ) class ...
Convert a stream completion response to a stream chat response.
36,592
import logging import os import time from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union import openai from deprecated import deprecated from openai.types.chat import ChatCompletionMessageParam, ChatCompletionMessageToolCall from openai.types.chat.chat_completion_chunk import ChoiceDelt...
null
36,593
import logging import os import time from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union import openai from deprecated import deprecated from openai.types.chat import ChatCompletionMessageParam, ChatCompletionMessageToolCall from openai.types.chat.chat_completion_chunk import ChoiceDelt...
null
36,594
import logging import os import time from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union import openai from deprecated import deprecated from openai.types.chat import ChatCompletionMessageParam, ChatCompletionMessageToolCall from openai.types.chat.chat_completion_chunk import ChoiceDelt...
Convert generic messages to OpenAI message dicts.
36,595
import logging import os import time from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union import openai from deprecated import deprecated from openai.types.chat import ChatCompletionMessageParam, ChatCompletionMessageToolCall from openai.types.chat.chat_completion_chunk import ChoiceDelt...
Convert openai message dicts to generic messages.
36,596
import logging import os import time from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union import openai from deprecated import deprecated from openai.types.chat import ChatCompletionMessageParam, ChatCompletionMessageToolCall from openai.types.chat.chat_completion_chunk import ChoiceDelt...
Convert openai message dicts to generic messages.
36,597
import logging import os import time from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union import openai from deprecated import deprecated from openai.types.chat import ChatCompletionMessageParam, ChatCompletionMessageToolCall from openai.types.chat.chat_completion_chunk import ChoiceDelt...
Deprecated in favor of `to_openai_tool`. Convert pydantic class to OpenAI function.
36,598
import logging import os import time from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union import openai from deprecated import deprecated from openai.types.chat import ChatCompletionMessageParam, ChatCompletionMessageToolCall from openai.types.chat.chat_completion_chunk import ChoiceDelt...
"Resolve OpenAI credentials. The order of precedence is: 1. param 2. env 3. openai module 4. default
36,599
import logging import os import time from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union import openai from deprecated import deprecated from openai.types.chat import ChatCompletionMessageParam, ChatCompletionMessageToolCall from openai.types.chat.chat_completion_chunk import ChoiceDelt...
Checks the validity of the associated token, if any, and tries to refresh it using the credentials available in the current context. Different authentication methods are tried, in order, until a successful one is found as defined at the package `azure-indentity`.
36,600
import logging import os import time from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union import openai from deprecated import deprecated from openai.types.chat import ChatCompletionMessageParam, ChatCompletionMessageToolCall from openai.types.chat.chat_completion_chunk import ChoiceDelt...
null
36,601
import base64 from typing import Any, Dict, Union from llama_index.legacy.llms import ChatMessage, MessageRole def is_gemini_model(model: str) -> bool: return model.startswith("gemini")
null
36,602
import base64 from typing import Any, Dict, Union from llama_index.legacy.llms import ChatMessage, MessageRole def create_gemini_client(model: str) -> Any: from vertexai.preview.generative_models import GenerativeModel return GenerativeModel(model_name=model)
null
36,603
import logging from importlib.metadata import version from types import ModuleType from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type import openai from packaging.version import parse from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, ...
Use tenacity to retry the completion call.
36,604
import logging from importlib.metadata import version from types import ModuleType from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type import openai from packaging.version import parse from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, ...
Convert generic messages to OpenAI message dicts.
36,605
import logging from importlib.metadata import version from types import ModuleType from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type import openai from packaging.version import parse from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, ...
Convert openai message dicts to generic messages.
36,606
import logging from importlib.metadata import version from types import ModuleType from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type import openai from packaging.version import parse from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, ...
Convert pydantic class to OpenAI function.
36,607
import logging from importlib.metadata import version from types import ModuleType from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type import openai from packaging.version import parse from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, ...
"Resolve KonkoAI credentials. The order of precedence is: 1. param 2. env 3. konkoai module 4. default
36,608
import logging from importlib.metadata import version from types import ModuleType from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type import openai from packaging.version import parse from tenacity import ( before_sleep_log, retry, retry_if_exception_type, stop_after_attempt, ...
Use tenacity to retry the async completion call.
36,609
from typing import Dict MISTRALAI_MODELS: Dict[str, int] = { "mistral-tiny": 32000, "mistral-small": 32000, "mistral-medium": 32000, } def mistralai_modelname_to_contextsize(modelname: str) -> int: if modelname not in MISTRALAI_MODELS: raise ValueError( f"Unknown model: {modelname}....
null
36,610
import json from typing import Any, Dict, Sequence, Tuple import httpx from httpx import Timeout from llama_index.legacy.bridge.pydantic import Field from llama_index.legacy.constants import DEFAULT_CONTEXT_WINDOW, DEFAULT_NUM_OUTPUTS from llama_index.legacy.core.llms.types import ( ChatMessage, ChatResponse, ...
null
36,611
from typing import TYPE_CHECKING, List from llama_index.legacy.core.llms.types import LLMMetadata from llama_index.legacy.llms.anthropic import Anthropic from llama_index.legacy.llms.anthropic_utils import CLAUDE_MODELS from llama_index.legacy.llms.openai import OpenAI from llama_index.legacy.llms.openai_utils import (...
Generate metadata for a Language Model (LLM) instance. This function takes an instance of a Language Model (LLM) and generates metadata based on the provided instance. The metadata includes information such as the context window, number of output tokens, chat model status, and model name. Parameters: llm (LLM): An inst...
36,612
from typing import TYPE_CHECKING, List from llama_index.legacy.core.llms.types import LLMMetadata from llama_index.legacy.llms.anthropic import Anthropic from llama_index.legacy.llms.anthropic_utils import CLAUDE_MODELS from llama_index.legacy.llms.openai import OpenAI from llama_index.legacy.llms.openai_utils import (...
null
36,613
import typing from typing import Sequence, Union from llama_index.legacy.core.llms.types import MessageRole from llama_index.legacy.llms.base import ( ChatMessage, ChatResponse, CompletionResponse, ) def _error_if_finished_early(candidate: "glm.Candidate") -> None: # type: ignore[name-defined] # only until...
null
36,614
import typing from typing import Sequence, Union from llama_index.legacy.core.llms.types import MessageRole from llama_index.legacy.llms.base import ( ChatMessage, ChatResponse, CompletionResponse, ) ROLES_FROM_GEMINI = {v: k for k, v in ROLES_TO_GEMINI.items()} def _error_if_finished_early(candidate: "glm....
null
36,615
import typing from typing import Sequence, Union from llama_index.legacy.core.llms.types import MessageRole from llama_index.legacy.llms.base import ( ChatMessage, ChatResponse, CompletionResponse, ) ROLES_TO_GEMINI = { MessageRole.USER: "user", MessageRole.ASSISTANT: "model", ## Gemini only has...
Convert ChatMessages to Gemini-specific history, including ImageDocuments.
36,616
import typing from typing import Sequence, Union from llama_index.legacy.core.llms.types import MessageRole from llama_index.legacy.llms.base import ( ChatMessage, ChatResponse, CompletionResponse, ) ROLES_TO_GEMINI = { MessageRole.USER: "user", MessageRole.ASSISTANT: "model", ## Gemini only has...
null
36,617
from http import HTTPStatus from typing import Any, Dict, List, Sequence from llama_index.legacy.core.llms.types import ( ChatMessage, ChatResponse, CompletionResponse, ) class CompletionResponse(BaseModel): """ Completion response. Fields: text: Text content of the response if not str...
null
36,618
from http import HTTPStatus from typing import Any, Dict, List, Sequence from llama_index.legacy.core.llms.types import ( ChatMessage, ChatResponse, CompletionResponse, ) class ChatMessage(BaseModel): """Chat message.""" role: MessageRole = MessageRole.USER content: Optional[Any] = "" addi...
null
36,619
from http import HTTPStatus from typing import Any, Dict, List, Sequence from llama_index.legacy.core.llms.types import ( ChatMessage, ChatResponse, CompletionResponse, ) class ChatMessage(BaseModel): def __str__(self) -> str: def chat_message_to_dashscope_messages( chat_messages: Sequence[ChatMe...
null
36,620
from typing import Dict, Sequence from llama_index.legacy.core.llms.types import ChatMessage, MessageRole CLAUDE_MODELS: Dict[str, int] = { "claude-instant-1": 100000, "claude-instant-1.2": 100000, "claude-2": 100000, "claude-2.0": 100000, "claude-2.1": 200000, } def anthropic_modelname_to_contexts...
null
36,621
from typing import Any, Dict, List, Optional, Sequence, Tuple from llama_index.legacy.core.llms.types import ChatMessage, MessageRole from llama_index.legacy.llms.generic_utils import get_from_param_or_env def _message_to_anyscale_prompt(message: ChatMessage) -> Dict[str, Any]: class ChatMessage(BaseModel): def _...
null