- 
                Notifications
    You must be signed in to change notification settings 
- Fork 10
Support other infini-gram functionalities here #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            liujch1998
  wants to merge
  11
  commits into
  main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
other-endpoints
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            11 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      926e471
              
                Import other infini-gram functionalities here
              
              
                 40ff4e5
              
                Support string query; Set max and default values of query parameters
              
              
                 c375492
              
                Add tests to API & other misc scripts
              
              
                 901430d
              
                Sync tokenize_to_list() with tokenize()
              
              
                 e5d21b1
              
                Address comments
              
              
                liujch1998 350817a
              
                Add more doc endpoints
              
              
                liujch1998 37d0630
              
                Fix doc endpoints
              
              
                liujch1998 5ad362c
              
                Fix doc endpoints
              
              
                liujch1998 e60fced
              
                Fix doc endpoints
              
              
                liujch1998 79ac39f
              
                Fix doc endpoints
              
              
                liujch1998 42cd9d0
              
                Use infini-gram in pypi
              
              
                liujch1998 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,9 +1,112 @@ | ||
| from fastapi import APIRouter | ||
| from infini_gram_processor.index_mappings import AvailableInfiniGramIndexId | ||
| from infini_gram_processor.models import ( | ||
| InfiniGramFindRequest, | ||
| FindResponse, | ||
| InfiniGramFindCnfRequest, | ||
| FindCnfResponse, | ||
| InfiniGramCountRequest, | ||
| CountResponse, | ||
| InfiniGramCountCnfRequest, | ||
| CountCnfResponse, | ||
| InfiniGramProbRequest, | ||
| ProbResponse, | ||
| InfiniGramNtdRequest, | ||
| NtdResponse, | ||
| InfiniGramInfgramProbRequest, | ||
| InfgramProbResponse, | ||
| InfiniGramInfgramNtdRequest, | ||
| InfgramNtdResponse, | ||
| ) | ||
| from src.infinigram.infini_gram_dependency import InfiniGramProcessorDependency | ||
|  | ||
| infinigram_router = APIRouter() | ||
|  | ||
|  | ||
| @infinigram_router.get(path="/indexes") | ||
| def get_available_indexes() -> list[AvailableInfiniGramIndexId]: | ||
| return [index for index in AvailableInfiniGramIndexId] | ||
|  | ||
|  | ||
| @infinigram_router.post(path="/{index}/find", description="Find the locations of an n-gram in the index") | ||
| def find( | ||
| infini_gram_processor: InfiniGramProcessorDependency, | ||
| body: InfiniGramFindRequest, | ||
| ) -> FindResponse: | ||
| return infini_gram_processor.find( | ||
| query=body.query, | ||
| ) | ||
|  | ||
|  | ||
| @infinigram_router.post(path="/{index}/find_cnf", description="Find the locations of a CNF query in the index") | ||
| def find_cnf( | ||
| infini_gram_processor: InfiniGramProcessorDependency, | ||
| body: InfiniGramFindCnfRequest, | ||
| ) -> FindCnfResponse: | ||
| return infini_gram_processor.find_cnf( | ||
| query=body.query, | ||
| max_clause_freq=body.max_clause_freq, | ||
| max_diff_tokens=body.max_diff_tokens, | ||
| ) | ||
|  | ||
|  | ||
| @infinigram_router.post(path="/{index}/count", description="Count the number of times an n-gram appears in the index") | ||
| def count( | ||
| infini_gram_processor: InfiniGramProcessorDependency, | ||
| body: InfiniGramCountRequest, | ||
| ) -> CountResponse: | ||
| return infini_gram_processor.count(query=body.query) | ||
|  | ||
|  | ||
| @infinigram_router.post(path="/{index}/count_cnf", description="Count the number of times a CNF query appears in the index") | ||
| def count_cnf( | ||
| infini_gram_processor: InfiniGramProcessorDependency, | ||
| body: InfiniGramCountCnfRequest, | ||
| ) -> CountCnfResponse: | ||
| return infini_gram_processor.count_cnf( | ||
| query=body.query, | ||
| max_clause_freq=body.max_clause_freq, | ||
| max_diff_tokens=body.max_diff_tokens, | ||
| ) | ||
|  | ||
|  | ||
| @infinigram_router.post(path="/{index}/prob", description="Compute the n-gram probability of the last token conditioned on all previous tokens") | ||
| def prob( | ||
| infini_gram_processor: InfiniGramProcessorDependency, | ||
| body: InfiniGramProbRequest, | ||
| ) -> ProbResponse: | ||
| return infini_gram_processor.prob( | ||
| query=body.query, | ||
| ) | ||
|  | ||
|  | ||
| @infinigram_router.post(path="/{index}/ntd", description="Compute the distribution of next token conditioned on all tokens in the query according to the n-gram model") | ||
| def ntd( | ||
| infini_gram_processor: InfiniGramProcessorDependency, | ||
| body: InfiniGramNtdRequest, | ||
| ) -> NtdResponse: | ||
| return infini_gram_processor.ntd( | ||
| query=body.query, | ||
| max_support=body.max_support, | ||
| ) | ||
|  | ||
|  | ||
| @infinigram_router.post(path="/{index}/infgram_prob", description="Compute the infinity-gram probability of the last token conditioned on all previous tokens") | ||
| def infgram_prob( | ||
| infini_gram_processor: InfiniGramProcessorDependency, | ||
| body: InfiniGramInfgramProbRequest, | ||
| ) -> InfgramProbResponse: | ||
| return infini_gram_processor.infgram_prob( | ||
| query=body.query, | ||
| ) | ||
|  | ||
|  | ||
| @infinigram_router.post(path="/{index}/infgram_ntd", description="Compute the distribution of next token conditioned on all tokens in the query according to the infinity-gram model") | ||
| def infgram_ntd( | ||
| infini_gram_processor: InfiniGramProcessorDependency, | ||
| body: InfiniGramInfgramNtdRequest, | ||
| ) -> InfgramNtdResponse: | ||
| return infini_gram_processor.infgram_ntd( | ||
| query=body.query, | ||
| max_support=body.max_support, | ||
| ) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed this function to give way to a regular version of
get_documents_by_pointers