id int64 0 190k | prompt stringlengths 21 13.4M | docstring stringlengths 1 12k ⌀ |
|---|---|---|
36,204 | from typing import Dict, Sequence, Tuple
from llama_index.core.base.llms.types import ChatMessage, MessageRole
class MessageRole(str, Enum):
"""Message role."""
SYSTEM = "system"
USER = "user"
ASSISTANT = "assistant"
FUNCTION = "function"
TOOL = "tool"
CHATBOT = "chatbot"
MODEL = "mode... | null |
36,205 | import logging
from typing import Any, Callable, Optional
import google.api_core
import vertexai
from tenacity import (
before_sleep_log,
retry,
retry_if_exception_type,
stop_after_attempt,
wait_exponential,
)
from vertexai.language_models import ChatMessage as VertexChatMessage
from vertexai.langua... | Use tenacity to retry the completion call. |
36,206 | import logging
from typing import Any, Callable, Optional
import google.api_core
import vertexai
from tenacity import (
before_sleep_log,
retry,
retry_if_exception_type,
stop_after_attempt,
wait_exponential,
)
from vertexai.language_models import ChatMessage as VertexChatMessage
from vertexai.langua... | Use tenacity to retry the completion call. |
36,207 | import logging
from typing import Any, Callable, Optional
import google.api_core
import vertexai
from tenacity import (
before_sleep_log,
retry,
retry_if_exception_type,
stop_after_attempt,
wait_exponential,
)
from vertexai.language_models import ChatMessage as VertexChatMessage
from vertexai.langua... | 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,208 | import logging
from typing import Any, Callable, Optional
import google.api_core
import vertexai
from tenacity import (
before_sleep_log,
retry,
retry_if_exception_type,
stop_after_attempt,
wait_exponential,
)
from vertexai.language_models import ChatMessage as VertexChatMessage
from vertexai.langua... | null |
36,209 | import logging
from typing import Any, Callable, Optional
import google.api_core
import vertexai
from tenacity import (
before_sleep_log,
retry,
retry_if_exception_type,
stop_after_attempt,
wait_exponential,
)
from vertexai.language_models import ChatMessage as VertexChatMessage
from vertexai.langua... | 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,210 | import logging
from typing import Any, Callable, Optional
import google.api_core
import vertexai
from tenacity import (
before_sleep_log,
retry,
retry_if_exception_type,
stop_after_attempt,
wait_exponential,
)
from vertexai.language_models import ChatMessage as VertexChatMessage
from vertexai.langua... | null |
36,211 | import base64
from typing import Any, Dict, Union
from llama_index.core.llms import ChatMessage, MessageRole
def is_gemini_model(model: str) -> bool:
return model.startswith("gemini") | null |
36,212 | import base64
from typing import Any, Dict, Union
from llama_index.core.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,213 | import time
import uuid
from typing import Any, Dict, Optional
import numpy as np
def parse_input(
input_text: str, tokenizer: Any, end_id: int, remove_input_padding: bool
) -> Any:
try:
import torch
except ImportError:
raise ImportError("nvidia_tensorrt requires `pip install torch`.")
... | null |
36,214 | import time
import uuid
from typing import Any, Dict, Optional
import numpy as np
def remove_extra_eos_ids(outputs: Any) -> Any:
outputs.reverse()
while outputs and outputs[0] == 2:
outputs.pop(0)
outputs.reverse()
outputs.append(2)
return outputs
def get_output(
output_ids: Any,
in... | null |
36,215 | import time
import uuid
from typing import Any, Dict, Optional
import numpy as np
The provided code snippet includes necessary dependencies for implementing the `generate_completion_dict` function. Write a Python function `def generate_completion_dict( text_str: str, model: Any, model_path: Optional[str] ) -> Dict... | Generate a dictionary for text completion details. Returns: dict: A dictionary containing completion details. |
36,216 | import json
from typing import Iterable, List
import requests
def get_response(response: requests.Response) -> List[str]:
data = json.loads(response.content)
return data["text"] | null |
36,217 | import json
from typing import Iterable, List
import requests
def post_http_request(
api_url: str, sampling_params: dict = {}, stream: bool = False
) -> requests.Response:
headers = {"User-Agent": "Test Client"}
sampling_params["stream"] = stream
return requests.post(api_url, headers=headers, json=sam... | null |
36,218 | import json
from typing import Iterable, List
import requests
def get_streaming_response(response: requests.Response) -> Iterable[List[str]]:
for chunk in response.iter_lines(
chunk_size=8192, decode_unicode=False, delimiter=b"\0"
):
if chunk:
data = json.loads(chunk.decode("utf-8")... | null |
36,219 | import logging
from typing import Any, Callable, Dict, List, Optional, Sequence
from llama_index.core.base.llms.types import ChatMessage
from tenacity import (
before_sleep_log,
retry,
retry_if_exception_type,
stop_after_attempt,
wait_exponential,
)
def _create_retry_decorator(max_retries: int) -> C... | Use tenacity to retry the completion call. |
36,220 | import logging
from typing import Any, Callable, Dict, List, Optional, Sequence
from llama_index.core.base.llms.types import ChatMessage
from tenacity import (
before_sleep_log,
retry,
retry_if_exception_type,
stop_after_attempt,
wait_exponential,
)
def _create_retry_decorator(max_retries: int) -> C... | Use tenacity to retry the async completion call. |
36,221 | import logging
from typing import Any, Callable, Dict, List, Optional, Sequence
from llama_index.core.base.llms.types import ChatMessage
from tenacity import (
before_sleep_log,
retry,
retry_if_exception_type,
stop_after_attempt,
wait_exponential,
)
ALL_AVAILABLE_MODELS = {**COMMAND_MODELS, **GENERA... | null |
36,222 | import logging
from typing import Any, Callable, Dict, List, Optional, Sequence
from llama_index.core.base.llms.types import ChatMessage
from tenacity import (
before_sleep_log,
retry,
retry_if_exception_type,
stop_after_attempt,
wait_exponential,
)
COMMAND_MODELS = {
"command-r": 128000,
"c... | null |
36,223 | import logging
from typing import Any, Callable, Dict, List, Optional, Sequence
from llama_index.core.base.llms.types import ChatMessage
from tenacity import (
before_sleep_log,
retry,
retry_if_exception_type,
stop_after_attempt,
wait_exponential,
)
class ChatMessage(BaseModel):
"""Chat message... | null |
36,224 | import logging
import os
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union
from deprecated import deprecated
from llama_index.core.base.llms.types import ChatMessage
from llama_index.core.bridge.pydantic import BaseModel
from llama_index.core.base.llms.generic_utils import get_from_pa... | null |
36,225 | import logging
import os
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union
from deprecated import deprecated
from llama_index.core.base.llms.types import ChatMessage
from llama_index.core.bridge.pydantic import BaseModel
from llama_index.core.base.llms.generic_utils import get_from_pa... | null |
36,226 | import logging
import os
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union
from deprecated import deprecated
from llama_index.core.base.llms.types import ChatMessage
from llama_index.core.bridge.pydantic import BaseModel
from llama_index.core.base.llms.generic_utils import get_from_pa... | Convert generic messages to OpenAI message dicts. |
36,227 | import logging
import os
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union
from deprecated import deprecated
from llama_index.core.base.llms.types import ChatMessage
from llama_index.core.bridge.pydantic import BaseModel
from llama_index.core.base.llms.generic_utils import get_from_pa... | Convert openai message dicts to generic messages. |
36,228 | import logging
import os
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union
from deprecated import deprecated
from llama_index.core.base.llms.types import ChatMessage
from llama_index.core.bridge.pydantic import BaseModel
from llama_index.core.base.llms.generic_utils import get_from_pa... | Convert openai message dicts to generic messages. |
36,229 | import logging
import os
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union
from deprecated import deprecated
from llama_index.core.base.llms.types import ChatMessage
from llama_index.core.bridge.pydantic import BaseModel
from llama_index.core.base.llms.generic_utils import get_from_pa... | Deprecated in favor of `to_openai_tool`. Convert pydantic class to OpenAI function. |
36,230 | import logging
import os
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union
from deprecated import deprecated
from llama_index.core.base.llms.types import ChatMessage
from llama_index.core.bridge.pydantic import BaseModel
from llama_index.core.base.llms.generic_utils import get_from_pa... | "Resolve OpenAI credentials. The order of precedence is: 1. param 2. env 3. openai module 4. default |
36,231 | import io
import json
from typing import Any, Dict, Sequence, Tuple
import httpx
from httpx import Timeout
from llama_index.core.base.llms.types import (
ChatMessage,
ChatResponse,
CompletionResponse,
CompletionResponseGen,
LLMMetadata,
MessageRole,
)
from llama_index.core.bridge.pydantic import... | null |
36,232 | import os
from typing import Optional, Union
WATSONX_MODELS = {
"google/flan-t5-xxl": 4096,
"google/flan-ul2": 4096,
"bigscience/mt0-xxl": 4096,
"eleutherai/gpt-neox-20b": 8192,
"bigcode/starcoder": 8192,
"meta-llama/llama-2-70b-chat": 4096,
"ibm/mpt-7b-instruct2": 2048,
"ibm/granite-13b... | Calculate the maximum number of tokens possible to generate for a model. Args: model_id: The model name we want to know the context size for. Returns: The maximum context size |
36,233 | import os
from typing import Optional, Union
The provided code snippet includes necessary dependencies for implementing the `get_from_param_or_env_without_error` function. Write a Python function `def get_from_param_or_env_without_error( param: Optional[str] = None, env_key: Optional[str] = None, ) -> Union[st... | Get a value from a param or an environment variable without error. |
36,234 | import time
from typing import Any, Optional
from azure.core.exceptions import ClientAuthenticationError
from azure.identity import DefaultAzureCredential
The provided code snippet includes necessary dependencies for implementing the `refresh_openai_azuread_token` function. Write a Python function `def refresh_openai_... | 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,235 | import time
from typing import Any, Optional
from azure.core.exceptions import ClientAuthenticationError
from azure.identity import DefaultAzureCredential
def resolve_from_aliases(*args: Optional[str]) -> Optional[str]:
for arg in args:
if arg is not None:
return arg
return None | null |
36,236 | import logging
from typing import Any, Callable, Dict, List, Optional, Sequence, Type
from llama_index.core.base.llms.types import ChatMessage
from llama_index.core.bridge.pydantic import BaseModel
from openai.resources import Completions
from tenacity import (
before_sleep_log,
retry,
retry_if_exception_ty... | Use tenacity to retry the completion call. |
36,237 | import logging
from typing import Any, Callable, Dict, List, Optional, Sequence, Type
from llama_index.core.base.llms.types import ChatMessage
from llama_index.core.bridge.pydantic import BaseModel
from openai.resources import Completions
from tenacity import (
before_sleep_log,
retry,
retry_if_exception_ty... | Use tenacity to retry the async completion call. |
36,238 | import logging
from typing import Any, Callable, Dict, List, Optional, Sequence, Type
from llama_index.core.base.llms.types import ChatMessage
from llama_index.core.bridge.pydantic import BaseModel
from openai.resources import Completions
from tenacity import (
before_sleep_log,
retry,
retry_if_exception_ty... | 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,239 | import logging
from typing import Any, Callable, Dict, List, Optional, Sequence, Type
from llama_index.core.base.llms.types import ChatMessage
from llama_index.core.bridge.pydantic import BaseModel
from openai.resources import Completions
from tenacity import (
before_sleep_log,
retry,
retry_if_exception_ty... | null |
36,240 | import logging
from typing import Any, Callable, Dict, List, Optional, Sequence, Type
from llama_index.core.base.llms.types import ChatMessage
from llama_index.core.bridge.pydantic import BaseModel
from openai.resources import Completions
from tenacity import (
before_sleep_log,
retry,
retry_if_exception_ty... | null |
36,241 | import logging
from typing import Any, Callable, Dict, List, Optional, Sequence, Type
from llama_index.core.base.llms.types import ChatMessage
from llama_index.core.bridge.pydantic import BaseModel
from openai.resources import Completions
from tenacity import (
before_sleep_log,
retry,
retry_if_exception_ty... | Convert generic messages to OpenAI message dicts. |
36,242 | import logging
from typing import Any, Callable, Dict, List, Optional, Sequence, Type
from llama_index.core.base.llms.types import ChatMessage
from llama_index.core.bridge.pydantic import BaseModel
from openai.resources import Completions
from tenacity import (
before_sleep_log,
retry,
retry_if_exception_ty... | Convert litellm.utils.Message instance to generic message. |
36,243 | import logging
from typing import Any, Callable, Dict, List, Optional, Sequence, Type
from llama_index.core.base.llms.types import ChatMessage
from llama_index.core.bridge.pydantic import BaseModel
from openai.resources import Completions
from tenacity import (
before_sleep_log,
retry,
retry_if_exception_ty... | Convert openai message dicts to generic messages. |
36,244 | import logging
from typing import Any, Callable, Dict, List, Optional, Sequence, Type
from llama_index.core.base.llms.types import ChatMessage
from llama_index.core.bridge.pydantic import BaseModel
from openai.resources import Completions
from tenacity import (
before_sleep_log,
retry,
retry_if_exception_ty... | Convert pydantic class to OpenAI function. |
36,245 | import logging
from typing import Any, Callable, Dict, List, Optional, Sequence, Type
from llama_index.core.base.llms.types import ChatMessage
from llama_index.core.bridge.pydantic import BaseModel
from openai.resources import Completions
from tenacity import (
before_sleep_log,
retry,
retry_if_exception_ty... | null |
36,246 | from typing import Dict
MISTRALAI_MODELS: Dict[str, int] = {
"mistral-tiny": 32000,
"mistral-small": 32000,
"mistral-medium": 32000,
"mistral-large": 32000,
"open-mixtral-8x7b": 32000,
"open-mistral-7b": 32000,
"mistral-small-latest": 32000,
"mistral-medium-latest": 32000,
"mistral-l... | null |
36,247 | from typing import Dict
ALL_AVAILABLE_MODELS = {
**LLAMA_MODELS,
}
DISCONTINUED_MODELS: Dict[str, int] = {}
The provided code snippet includes necessary dependencies for implementing the `everlyai_modelname_to_contextsize` function. Write a Python function `def everlyai_modelname_to_contextsize(modelname: str) -> ... | 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 = everlyai_modelname_to_contextsize(model_name) |
36,248 | import logging
from typing import Any, Callable, List, Optional, Tuple, Union
from llama_index.core.base.base_retriever import BaseRetriever
from llama_index.core.base.embeddings.base import BaseEmbedding
from llama_index.core.callbacks.base import CallbackManager
from llama_index.core.constants import DEFAULT_SIMILARI... | null |
36,249 | import logging
from typing import Any, Callable, List, Optional, Tuple, Union
from llama_index.core.base.base_retriever import BaseRetriever
from llama_index.core.base.embeddings.base import BaseEmbedding
from llama_index.core.callbacks.base import CallbackManager
from llama_index.core.constants import DEFAULT_SIMILARI... | null |
36,250 | import logging
from typing import Callable, List, Optional, cast
from llama_index.core.base.base_retriever import BaseRetriever
from llama_index.core.callbacks.base import CallbackManager
from llama_index.core.constants import DEFAULT_SIMILARITY_TOP_K
from llama_index.core.indices.keyword_table.utils import simple_extr... | null |
36,251 | from typing import Any
from llama_index.core.callbacks.base_handler import BaseCallbackHandler
from deepeval.integrations.llama_index.callback import LlamaIndexCallbackHandler
class BaseCallbackHandler(ABC):
"""Base callback handler that can be used to track event starts and ends."""
def __init__(
sel... | null |
36,252 | from typing import Any
from llama_index.core.callbacks.base_handler import BaseCallbackHandler
from honeyhive.utils.llamaindex_tracer import HoneyHiveLlamaIndexTracer
class BaseCallbackHandler(ABC):
"""Base callback handler that can be used to track event starts and ends."""
def __init__(
self,
... | null |
36,253 | from typing import Any
from llama_index.core.callbacks.base_handler import BaseCallbackHandler
class BaseCallbackHandler(ABC):
"""Base callback handler that can be used to track event starts and ends."""
def __init__(
self,
event_starts_to_ignore: List[CBEventType],
event_ends_to_ignor... | null |
36,254 | from typing import Any
from llama_index.core.callbacks.base_handler import BaseCallbackHandler
class BaseCallbackHandler(ABC):
"""Base callback handler that can be used to track event starts and ends."""
def __init__(
self,
event_starts_to_ignore: List[CBEventType],
event_ends_to_ignor... | null |
36,255 | from typing import Any
from llama_index.core.callbacks.base_handler import BaseCallbackHandler
from langfuse.llama_index import LlamaIndexCallbackHandler
class BaseCallbackHandler(ABC):
"""Base callback handler that can be used to track event starts and ends."""
def __init__(
self,
event_start... | null |
36,256 | import importlib
import uuid
from dataclasses import dataclass, field, fields
from datetime import datetime
from types import ModuleType
from typing import (
TYPE_CHECKING,
Any,
Callable,
Dict,
Iterable,
List,
Optional,
Tuple,
TypeVar,
)
from llama_index.core.base.llms.types import C... | Generates a random ID. Returns: str: A random ID. |
36,257 | import importlib
import uuid
from dataclasses import dataclass, field, fields
from datetime import datetime
from types import ModuleType
from typing import (
TYPE_CHECKING,
Any,
Callable,
Dict,
Iterable,
List,
Optional,
Tuple,
TypeVar,
)
from llama_index.core.base.llms.types import C... | Converts a list of BaseDataType to a pandas dataframe. Args: data (Iterable[BaseDataType]): A list of BaseDataType. Returns: DataFrame: The converted pandas dataframe. |
36,262 | import logging
from typing import Any, Dict, Generator, List, Optional, Tuple, Type, Union, cast
from llama_index.agent.openai.utils import resolve_tool_choice
from llama_index.core.llms.llm import LLM
from llama_index.core.program.llm_prompt_program import BaseLLMFunctionProgram
from llama_index.core.program.utils imp... | Default OpenAI tool to choose. |
36,263 | import logging
from typing import Any, Dict, Generator, List, Optional, Tuple, Type, Union, cast
from llama_index.agent.openai.utils import resolve_tool_choice
from llama_index.core.llms.llm import LLM
from llama_index.core.program.llm_prompt_program import BaseLLMFunctionProgram
from llama_index.core.program.utils imp... | Extract JSON str from raw string and start index. |
36,264 | import logging
from typing import Any, Dict, Generator, List, Optional, Tuple, Type, Union, cast
from llama_index.agent.openai.utils import resolve_tool_choice
from llama_index.core.llms.llm import LLM
from llama_index.core.program.llm_prompt_program import BaseLLMFunctionProgram
from llama_index.core.program.utils imp... | null |
36,265 | from contextlib import contextmanager
from typing import TYPE_CHECKING, Callable, Iterator
from llama_index.core.llms.llm import LLM
from llama_index.llms.huggingface import HuggingFaceLLM
from llama_index.llms.llama_cpp import LlamaCPP
class LLM(BaseLLM):
system_prompt: Optional[str] = Field(
default=None... | Prepare for using the LM format enforcer. This builds the processing function that will be injected into the LLM to activate the LM Format Enforcer. |
36,266 | from contextlib import contextmanager
from typing import TYPE_CHECKING, Callable, Iterator
from llama_index.core.llms.llm import LLM
from llama_index.llms.huggingface import HuggingFaceLLM
from llama_index.llms.llama_cpp import LlamaCPP
class LLM(BaseLLM):
system_prompt: Optional[str] = Field(
default=None... | Activate the LM Format Enforcer for the given LLM. with activate_lm_format_enforcer(llm, lm_format_enforcer_fn): llm.complete(...) |
36,267 | import random
import re
import signal
from collections import defaultdict
from contextlib import contextmanager
from typing import Any, Dict, List, Optional, Set, Tuple
from llama_index.core.llms.llm import LLM
from llama_index.core.schema import BaseNode, MetadataMode, NodeWithScore, QueryBundle
from llama_index.core.... | Time limit context manager. NOTE: copied from https://github.com/HazyResearch/evaporate. |
36,268 | import random
import re
import signal
from collections import defaultdict
from contextlib import contextmanager
from typing import Any, Dict, List, Optional, Set, Tuple
from llama_index.core.llms.llm import LLM
from llama_index.core.schema import BaseNode, MetadataMode, NodeWithScore, QueryBundle
from llama_index.core.... | Get function field from attribute. NOTE: copied from https://github.com/HazyResearch/evaporate. |
36,269 | import random
import re
import signal
from collections import defaultdict
from contextlib import contextmanager
from typing import Any, Dict, List, Optional, Set, Tuple
from llama_index.core.llms.llm import LLM
from llama_index.core.schema import BaseNode, MetadataMode, NodeWithScore, QueryBundle
from llama_index.core.... | Extract field dictionaries. |
36,270 | import logging
from enum import Enum
from http import HTTPStatus
from typing import Any, Dict, List, Optional, Union
from llama_index.core.bridge.pydantic import PrivateAttr
from llama_index.core.embeddings.multi_modal_base import MultiModalEmbedding
from llama_index.core.schema import ImageType
logger = logging.getLog... | Call DashScope text embedding. ref: https://help.aliyun.com/zh/dashscope/developer-reference/text-embedding-api-details. Args: model (str): The `DashScopeTextEmbeddingModels` text (Union[str, List[str]]): text or list text to embedding. Raises: ImportError: need import dashscope Returns: List[List[float]]: The list of ... |
36,271 | import logging
from enum import Enum
from http import HTTPStatus
from typing import Any, Dict, List, Optional, Union
from llama_index.core.bridge.pydantic import PrivateAttr
from llama_index.core.embeddings.multi_modal_base import MultiModalEmbedding
from llama_index.core.schema import ImageType
logger = logging.getLog... | Call DashScope batch text embedding. Args: model (str): The `DashScopeMultiModalEmbeddingModels` url (str): The url of the file to embedding which with lines of text to embedding. Raises: ImportError: Need install dashscope package. Returns: str: The url of the embedding result, format ref: https://help.aliyun.com/zh/d... |
36,272 | import logging
from enum import Enum
from http import HTTPStatus
from typing import Any, Dict, List, Optional, Union
from llama_index.core.bridge.pydantic import PrivateAttr
from llama_index.core.embeddings.multi_modal_base import MultiModalEmbedding
from llama_index.core.schema import ImageType
logger = logging.getLog... | Call DashScope multimodal embedding. ref: https://help.aliyun.com/zh/dashscope/developer-reference/one-peace-multimodal-embedding-api-details. Args: model (str): The `DashScopeBatchTextEmbeddingModels` input (str): The input of the embedding, eg: [{'factor': 1, 'text': '你好'}, {'factor': 2, 'audio': 'https://dashscope.o... |
36,273 | from typing import Optional, Tuple
from llama_index.core.base.llms.generic_utils import get_from_param_or_env
DEFAULT_ANYSCALE_API_BASE = "https://api.endpoints.anyscale.com/v1"
DEFAULT_ANYSCALE_API_VERSION = ""
def get_from_param_or_env(
key: str,
param: Optional[str] = None,
env_key: Optional[str] = None... | "Resolve OpenAI credentials. The order of precedence is: 1. param 2. env 3. openai module 4. default |
36,274 | from typing import Any, Dict, List, Optional
import httpx
from llama_index.core.base.embeddings.base import (
DEFAULT_EMBED_BATCH_SIZE,
BaseEmbedding,
)
from llama_index.core.bridge.pydantic import Field, PrivateAttr
from llama_index.core.callbacks import CallbackManager
from llama_index.embeddings.anyscale.uti... | Get embedding. NOTE: Copied from OpenAI's embedding utils: https://github.com/openai/openai-python/blob/main/openai/embeddings_utils.py Copied here to avoid importing unnecessary dependencies like matplotlib, plotly, scipy, sklearn. |
36,275 | from typing import Any, Dict, List, Optional
import httpx
from llama_index.core.base.embeddings.base import (
DEFAULT_EMBED_BATCH_SIZE,
BaseEmbedding,
)
from llama_index.core.bridge.pydantic import Field, PrivateAttr
from llama_index.core.callbacks import CallbackManager
from llama_index.embeddings.anyscale.uti... | Asynchronously get embedding. NOTE: Copied from OpenAI's embedding utils: https://github.com/openai/openai-python/blob/main/openai/embeddings_utils.py Copied here to avoid importing unnecessary dependencies like matplotlib, plotly, scipy, sklearn. |
36,276 | from typing import Any, Dict, List, Optional
import httpx
from llama_index.core.base.embeddings.base import (
DEFAULT_EMBED_BATCH_SIZE,
BaseEmbedding,
)
from llama_index.core.bridge.pydantic import Field, PrivateAttr
from llama_index.core.callbacks import CallbackManager
from llama_index.embeddings.anyscale.uti... | Get embeddings. NOTE: Copied from OpenAI's embedding utils: https://github.com/openai/openai-python/blob/main/openai/embeddings_utils.py Copied here to avoid importing unnecessary dependencies like matplotlib, plotly, scipy, sklearn. |
36,277 | from typing import Any, Dict, List, Optional
import httpx
from llama_index.core.base.embeddings.base import (
DEFAULT_EMBED_BATCH_SIZE,
BaseEmbedding,
)
from llama_index.core.bridge.pydantic import Field, PrivateAttr
from llama_index.core.callbacks import CallbackManager
from llama_index.embeddings.anyscale.uti... | Asynchronously get embeddings. NOTE: Copied from OpenAI's embedding utils: https://github.com/openai/openai-python/blob/main/openai/embeddings_utils.py Copied here to avoid importing unnecessary dependencies like matplotlib, plotly, scipy, sklearn. |
36,278 | from typing import Optional
import requests
def get_query_instruct_for_model_name(model_name: Optional[str]) -> str:
"""Get query text instruction for a given model name."""
if model_name in INSTRUCTOR_MODELS:
return DEFAULT_QUERY_INSTRUCTION
if model_name in BGE_MODELS:
if "zh" in model_nam... | null |
36,279 | from typing import Optional
import requests
def get_text_instruct_for_model_name(model_name: Optional[str]) -> str:
"""Get text instruction for a given model name."""
return DEFAULT_EMBED_INSTRUCTION if model_name in INSTRUCTOR_MODELS else ""
def format_text(
text: str, model_name: Optional[str], instructi... | null |
36,280 | from typing import Optional
import requests
def get_pooling_mode(model_name: Optional[str]) -> str:
pooling_config_url = (
f"https://huggingface.co/{model_name}/raw/main/1_Pooling/config.json"
)
try:
response = requests.get(pooling_config_url)
config_data = response.json()
... | null |
36,281 | from typing import Optional
def get_query_instruct_for_model_name(model_name: Optional[str]) -> str:
def format_query(
query: str, model_name: Optional[str], instruction: Optional[str] = None
) -> str:
if instruction is None:
instruction = get_query_instruct_for_model_name(model_name)
# NOTE: strip... | null |
36,282 | from typing import Optional
def get_text_instruct_for_model_name(model_name: Optional[str]) -> str:
"""Get text instruction for a given model name."""
return DEFAULT_EMBED_INSTRUCTION if model_name in INSTRUCTOR_MODELS else ""
def format_text(
text: str, model_name: Optional[str], instruction: Optional[str... | null |
36,283 | import logging
import os
from typing import Any, Callable, Optional, Tuple, Union
from llama_index.core.base.llms.generic_utils import get_from_param_or_env
from tenacity import (
before_sleep_log,
retry,
retry_if_exception_type,
stop_after_attempt,
stop_after_delay,
wait_exponential,
wait_r... | null |
36,284 | import logging
import os
from typing import Any, Callable, Optional, Tuple, Union
from llama_index.core.base.llms.generic_utils import get_from_param_or_env
from tenacity import (
before_sleep_log,
retry,
retry_if_exception_type,
stop_after_attempt,
stop_after_delay,
wait_exponential,
wait_r... | "Resolve OpenAI credentials. The order of precedence is: 1. param 2. env 3. openai module 4. default |
36,285 | from enum import Enum
from typing import Any, Dict, List, Optional, Tuple
import httpx
from llama_index.core.base.embeddings.base import BaseEmbedding
from llama_index.core.bridge.pydantic import Field, PrivateAttr
from llama_index.core.callbacks.base import CallbackManager
from llama_index.embeddings.openai.utils impo... | Get embedding. NOTE: Copied from OpenAI's embedding utils: https://github.com/openai/openai-python/blob/main/openai/embeddings_utils.py Copied here to avoid importing unnecessary dependencies like matplotlib, plotly, scipy, sklearn. |
36,286 | from enum import Enum
from typing import Any, Dict, List, Optional, Tuple
import httpx
from llama_index.core.base.embeddings.base import BaseEmbedding
from llama_index.core.bridge.pydantic import Field, PrivateAttr
from llama_index.core.callbacks.base import CallbackManager
from llama_index.embeddings.openai.utils impo... | Asynchronously get embedding. NOTE: Copied from OpenAI's embedding utils: https://github.com/openai/openai-python/blob/main/openai/embeddings_utils.py Copied here to avoid importing unnecessary dependencies like matplotlib, plotly, scipy, sklearn. |
36,287 | from enum import Enum
from typing import Any, Dict, List, Optional, Tuple
import httpx
from llama_index.core.base.embeddings.base import BaseEmbedding
from llama_index.core.bridge.pydantic import Field, PrivateAttr
from llama_index.core.callbacks.base import CallbackManager
from llama_index.embeddings.openai.utils impo... | Get embeddings. NOTE: Copied from OpenAI's embedding utils: https://github.com/openai/openai-python/blob/main/openai/embeddings_utils.py Copied here to avoid importing unnecessary dependencies like matplotlib, plotly, scipy, sklearn. |
36,288 | from enum import Enum
from typing import Any, Dict, List, Optional, Tuple
import httpx
from llama_index.core.base.embeddings.base import BaseEmbedding
from llama_index.core.bridge.pydantic import Field, PrivateAttr
from llama_index.core.callbacks.base import CallbackManager
from llama_index.embeddings.openai.utils impo... | Asynchronously get embeddings. NOTE: Copied from OpenAI's embedding utils: https://github.com/openai/openai-python/blob/main/openai/embeddings_utils.py Copied here to avoid importing unnecessary dependencies like matplotlib, plotly, scipy, sklearn. |
36,289 | from enum import Enum
from typing import Any, Dict, List, Optional, Tuple
import httpx
from llama_index.core.base.embeddings.base import BaseEmbedding
from llama_index.core.bridge.pydantic import Field, PrivateAttr
from llama_index.core.callbacks.base import CallbackManager
from llama_index.embeddings.openai.utils impo... | Get engine. |
36,290 | import json
import logging
import os
from abc import abstractmethod
from typing import Callable, Dict
import torch
import torch.nn.functional as F
from torch import Tensor, nn
The provided code snippet includes necessary dependencies for implementing the `get_activation_function` function. Write a Python function `def... | Get activation function. Args: name (str): Name of activation function. |
36,291 | from enum import Enum
from typing import Optional, List, Any, Dict, Union
import vertexai
from llama_index.core.base.embeddings.base import Embedding, BaseEmbedding
from llama_index.core.bridge.pydantic import PrivateAttr, Field
from llama_index.core.callbacks import CallbackManager
from llama_index.core.embeddings imp... | 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. |
36,292 | from enum import Enum
from typing import Optional, List, Any, Dict, Union
import vertexai
from llama_index.core.base.embeddings.base import Embedding, BaseEmbedding
from llama_index.core.bridge.pydantic import PrivateAttr, Field
from llama_index.core.callbacks import CallbackManager
from llama_index.core.embeddings imp... | null |
36,293 | from typing import Optional, Tuple
from llama_index.core.base.llms.generic_utils import get_from_param_or_env
DEFAULT_FIREWORKS_API_BASE = "https://api.endpoints.fireworks.com/v1"
DEFAULT_FIREWORKS_API_VERSION = ""
def get_from_param_or_env(
key: str,
param: Optional[str] = None,
env_key: Optional[str] = N... | "Resolve OpenAI credentials. The order of precedence is: 1. param 2. env 3. openai module 4. default |
36,294 | import logging
from typing import Any, Dict, Optional, Sequence, Tuple, List
import base64
import httpx
from llama_index.core.multi_modal_llms.generic_utils import encode_image
from llama_index.core.schema import ImageDocument
from llama_index.core.base.llms.generic_utils import get_from_param_or_env
def infer_image_mi... | null |
36,295 | import logging
from typing import Any, Dict, Optional, Sequence, Tuple, List
import base64
import httpx
from llama_index.core.multi_modal_llms.generic_utils import encode_image
from llama_index.core.schema import ImageDocument
from llama_index.core.base.llms.generic_utils import get_from_param_or_env
DEFAULT_ANTHROPIC_... | "Resolve Anthropic credentials. The order of precedence is: 1. param 2. env 3. anthropic module 4. default |
36,296 | import logging
from typing import Any, Dict, Optional, Sequence
from llama_index.core.multi_modal_llms.base import ChatMessage
from llama_index.core.multi_modal_llms.generic_utils import encode_image
from llama_index.core.schema import ImageDocument
def encode_image(image_path: str) -> str:
with open(image_path, "... | null |
36,297 | from typing import Any, Dict, Optional, Sequence, Tuple
from ollama import Client
from llama_index.core.base.llms.types import (
ChatMessage,
ChatResponse,
ChatResponseAsyncGen,
ChatResponseGen,
CompletionResponse,
CompletionResponseAsyncGen,
CompletionResponseGen,
MessageRole,
)
from ll... | null |
36,298 | from typing import Any, Dict, Optional, Sequence, Tuple
from ollama import Client
from llama_index.core.base.llms.types import (
ChatMessage,
ChatResponse,
ChatResponseAsyncGen,
ChatResponseGen,
CompletionResponse,
CompletionResponseAsyncGen,
CompletionResponseGen,
MessageRole,
)
from ll... | Convert messages to dicts. For use in ollama API |
36,299 | from http import HTTPStatus
from typing import Any, Dict, List, Sequence
from llama_index.core.base.llms.types import (
ChatMessage,
ChatResponse,
CompletionResponse,
)
from llama_index.core.schema import ImageDocument
class CompletionResponse(BaseModel):
"""
Completion response.
Fields:
... | null |
36,300 | from http import HTTPStatus
from typing import Any, Dict, List, Sequence
from llama_index.core.base.llms.types import (
ChatMessage,
ChatResponse,
CompletionResponse,
)
from llama_index.core.schema import ImageDocument
class ChatMessage(BaseModel):
"""Chat message."""
role: MessageRole = MessageRo... | null |
36,301 | from http import HTTPStatus
from typing import Any, Dict, List, Sequence
from llama_index.core.base.llms.types import (
ChatMessage,
ChatResponse,
CompletionResponse,
)
from llama_index.core.schema import ImageDocument
class ChatMessage(BaseModel):
"""Chat message."""
role: MessageRole = MessageRo... | null |
36,302 | from http import HTTPStatus
from typing import Any, Dict, List, Sequence
from llama_index.core.base.llms.types import (
ChatMessage,
ChatResponse,
CompletionResponse,
)
from llama_index.core.schema import ImageDocument
class ChatMessage(BaseModel):
"""Chat message."""
role: MessageRole = MessageRo... | null |
36,303 | from http import HTTPStatus
from typing import Any, Dict, List, Sequence
from llama_index.core.base.llms.types import (
ChatMessage,
ChatResponse,
CompletionResponse,
)
from llama_index.core.schema import ImageDocument
class ImageDocument(Document, ImageNode):
"""Data document containing an image."""
... | null |
36,304 | from http import HTTPStatus
from typing import Any, Dict, List, Optional, Sequence, Tuple
from llama_index.core.base.llms.types import (
ChatMessage,
ChatResponse,
ChatResponseAsyncGen,
ChatResponseGen,
CompletionResponse,
CompletionResponseAsyncGen,
CompletionResponseGen,
LLMMetadata,
... | null |
36,305 | import asyncio
import tempfile
from pathlib import Path
from typing import Any, Dict, List, Optional, Union, cast
from llama_index.core.readers import SimpleDirectoryReader
from llama_index.core.readers.base import BaseReader
from llama_index.core.schema import Document
async def download_file_from_opendal(op: Any, tem... | Download directory from opendal. |
36,306 | import re
YOUTUBE_URL_PATTERNS = [
r"^https?://(?:www\.)?youtube\.com/watch\?v=([\w-]+)",
r"^https?://(?:www\.)?youtube\.com/embed/([\w-]+)",
r"^https?://youtu\.be/([\w-]+)", # youtu.be does not use www
]
The provided code snippet includes necessary dependencies for implementing the `is_youtube_video` fun... | Returns whether the passed in `url` matches the various YouTube URL formats. |
36,307 | try:
import concurrent.futures
import os
import re
import imdb
import pandas as pd
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from s... | The main helper function to scrape data. Args: movie_name (str): The name of the movie along with the year webdriver_engine (str, optional): The webdriver engine to use. Defaults to "edge". generate_csv (bool, optional): whether to save the dataframe files. Defaults to False. multiprocessing (bool, optional): whether t... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.