signebedi / gptty

ChatGPT wrapper in your TTY
MIT License
50 stars 7 forks source link

[scripting] expose universalCompletion class in __init__.py #39

Closed signebedi closed 1 year ago

signebedi commented 1 year ago

[scripting] expose certain classes / structs via init.py We should expose certain classes / structs here. For example, the log dataframe.

signebedi commented 1 year ago

I think it is also worth creating a universalQuery class that can be used to create a query that (1) validates a passed model_name and, based on this, properly generates a query based on a question passed to a corresponding method, and then queries using a separate method.

class universalQuery:
  def __init__(self, model_name):
    ...

  def generate_query(self, question, tag): 
  # I think it's best for us to expect users to pull out the tag outside the context of this class method
    ...

  def submit_query_sync(self, query): # synchronous query
    ...

  def submit_query_async(self, query): # asynchronous query
    ...

We can expose this in init.py, even though it is not really how we do things.

signebedi commented 1 year ago

[scripting] extend the UniversalCompletion class with context generation We should extend the UniversalCompletion class with features that support generating context like in gptty.context.

    def build_context(self, 
                      prompt: str, 
                      context: List[Dict[str, str]], 
                      max_context_length: int, 
                      model_type: Optional[str] = None, 
                      context_keywords_only: bool = True, 
                      additional_context: str = "", 
                      ) -> Union[str, List[Dict[str, str]]]:
        """
        Builds a full query context for a given prompt and context.

        Parameters:
            prompt (str): The main prompt to build the context around.
            context (List[Dict[str, str]]): List of past prompts and responses.
            max_context_length (int): Maximum length of the context to return.
            model_type (Optional[str]): Type of the language model. If 'v1/chat/completions', return a list of dicts 
                                        with 'role' and 'content' keys. If not, return a string. Default is None.
            context_keywords_only (bool, optional): If True, use only the most common phrases and words from the context 
                                                    and additional context. Default is True.
            additional_context (str, optional): Additional context to add to the context. Default is an empty string.

        Returns:
            Union[str, List[Dict[str, str]]]: If `model_type` is 'v1/chat/completions', returns a list of dicts with 
                                              'role' and 'content' keys. If not, returns a string.
        """
        pass