Source code for langchain.llms.koboldai
import logging
from typing import Any, Dict, List, Optional
import requests
from langchain.callbacks.manager import CallbackManagerForLLMRun
from langchain.llms.base import LLM
logger = logging.getLogger(__name__)
[docs]def clean_url(url: str) -> str:
    """Remove trailing slash and /api from url if present."""
    if url.endswith("/api"):
        return url[:-4]
    elif url.endswith("/"):
        return url[:-1]
    else:
        return url
[docs]class KoboldApiLLM(LLM):
    """Kobold API language model.
    It includes several fields that can be used to control the text generation process.
    To use this class, instantiate it with the required parameters and call it with a
    prompt to generate text. For example:
        kobold = KoboldApiLLM(endpoint="http://localhost:5000")
        result = kobold("Write a story about a dragon.")
    This will send a POST request to the Kobold API with the provided prompt and
    generate text.
    """
    endpoint: str
    """The API endpoint to use for generating text."""
    use_story: Optional[bool] = False
    """ Whether or not to use the story from the KoboldAI GUI when generating text. """
    use_authors_note: Optional[bool] = False
    """Whether to use the author's note from the KoboldAI GUI when generating text.
    
    This has no effect unless use_story is also enabled.
    """
    use_world_info: Optional[bool] = False
    """Whether to use the world info from the KoboldAI GUI when generating text."""
    use_memory: Optional[bool] = False