Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (0.7%) to scientific vocabulary
Last synced: 6 months ago · JSON representation ·

Repository

Basic Info
  • Host: GitHub
  • Owner: tectiv3
  • License: mit
  • Language: Go
  • Default Branch: main
  • Size: 49.8 KB
Statistics
  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created 9 months ago · Last pushed 8 months ago
Metadata Files
Readme License Citation

README.md

anthropic-go

Extracted and refactored code for working with Anthropic API from https://github.com/diveagents/dive

Owner

  • Name: tectiv3
  • Login: tectiv3
  • Kind: user

Citation (citations.go)

package anthropic

import (
	"encoding/json"
	"fmt"
)

type CitationType string

const (
	CitationTypeCharLocation            CitationType = "char_location"
	CitationTypeWebSearchResultLocation CitationType = "web_search_result_location"
	CitationTypeURLCitation             CitationType = "url_citation"
)

// CitationSettings contains settings for citations in a message.
type CitationSettings struct {
	Enabled bool `json:"enabled"`
}

type Citation interface {
	IsCitation() bool
}

// CharLocation is a citation to a specific part of a document.
type CharLocation struct {
	Type           string `json:"type"` // "char_location"
	CitedText      string `json:"cited_text,omitempty"`
	DocumentIndex  int    `json:"document_index,omitempty"`
	DocumentTitle  string `json:"document_title,omitempty"`
	StartCharIndex int    `json:"start_char_index,omitempty"`
	EndCharIndex   int    `json:"end_char_index,omitempty"`
}

func (c *CharLocation) IsCitation() bool {
	return true
}

/*
   {
     "type": "web_search_result_location",
     "url": "https://en.wikipedia.org/wiki/Claude_Shannon",
     "title": "Claude Shannon - Wikipedia",
     "encrypted_index": "Eo8BCioIAhgBIiQyYjQ0OWJmZi1lNm..",
     "cited_text": "Claude Elwood Shannon (April 30, 1916 – ..."
   }
*/

// WebSearchResultLocation is a citation to a specific part of a web page.
type WebSearchResultLocation struct {
	Type           string `json:"type"` // "web_search_result_location"
	URL            string `json:"url"`
	Title          string `json:"title"`
	EncryptedIndex string `json:"encrypted_index,omitempty"`
	CitedText      string `json:"cited_text,omitempty"`
}

func (c *WebSearchResultLocation) IsCitation() bool {
	return true
}

type citationTypeIndicator struct {
	Type CitationType `json:"type"`
}

func unmarshalCitation(data []byte) (Citation, error) {
	var ct citationTypeIndicator
	if err := json.Unmarshal(data, &ct); err != nil {
		return nil, err
	}
	switch ct.Type {
	case CitationTypeCharLocation:
		var c *CharLocation
		if err := json.Unmarshal(data, &c); err != nil {
			return nil, err
		}
		return c, nil
	case CitationTypeWebSearchResultLocation:
		var c *WebSearchResultLocation
		if err := json.Unmarshal(data, &c); err != nil {
			return nil, err
		}
		return c, nil
	default:
		return nil, fmt.Errorf("unknown citation type: %s", ct.Type)
	}
}

func unmarshalCitations(data []byte) ([]Citation, error) {
	var results []Citation
	var items []json.RawMessage
	if err := json.Unmarshal(data, &items); err != nil {
		return nil, err
	}
	for _, item := range items {
		citation, err := unmarshalCitation(item)
		if err != nil {
			return nil, err
		}
		results = append(results, citation)
	}
	return results, nil
}

GitHub Events

Total
  • Release event: 1
  • Push event: 2
  • Create event: 3
Last Year
  • Release event: 1
  • Push event: 2
  • Create event: 3

Packages

  • Total packages: 1
  • Total downloads: unknown
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 1
proxy.golang.org: github.com/tectiv3/anthropic-go
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.4%
Average: 5.5%
Dependent repos count: 5.7%
Last synced: 6 months ago

Dependencies

go.mod go