Skip to content

Commit aa409b3

Browse files
committed
lint: Add separate more relaxed linting for exp tree
This is just local config for now.
1 parent ce4891f commit aa409b3

25 files changed

+51
-57
lines changed

.golangci-exp.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
linters:
2+
presets:
3+
- bugs
4+
- comment

.golangci.yaml

-7
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,3 @@ linters:
2121
- varnamelen
2222
- nlreturn
2323
- wrapcheck # TODO: we should probably enable this one (at least for new code).
24-
exclude-rules:
25-
- path: ^exp/.*.go
26-
linters:
27-
- errorlint
28-
# issues:
29-
# new: true
30-
# new-from-rev: HEAD

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ test:
1010
lint:
1111
golangci-lint run --color=always --sort-results --skip-dirs=exp ./...
1212

13+
.PHONY: lint-exp
14+
lint-exp:
15+
golangci-lint run --fix --config .golangci-exp.yaml ./...
16+
1317
.PHONY: lint-fix
1418
lint-fix:
1519
golangci-lint run --fix --skip-dirs=exp ./...

exp/agent/agents.go

-2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ func New(
4444
tools []tools.Tool,
4545
agentType AgentType,
4646
opts ...Options,
47-
4847
) (executor.AgentExecutor, error) {
49-
5048
options := defaultOptions()
5149
for _, opt := range opts {
5250
opt(&options)

exp/agent/mrkl/mrkl.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ func NewOneShotAgent(llm llms.LLM, tools []tools.Tool, opts map[string]any) (*On
5757
verbose: opts["verbose"].(bool),
5858
maxRetries: opts["maxRetries"].(int),
5959
}, nil
60-
6160
}
6261

6362
// Run is an implementation of the AgentExecutor interface. It takes a query as input
@@ -113,7 +112,7 @@ func (a *OneShotZeroAgent) nextStep(action schema.AgentAction) (string, error) {
113112

114113
// Use the updated resp in the next iteration
115114
return newResp["text"].(string), nil
116-
115+
}
117116
}
118117
func (a *OneShotZeroAgent) plan(info string) (*schema.AgentAction, *schema.AgentFinish) {
119118
action := getAgentAction(info)

exp/agent/mrkl/prompt.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import (
88
"github.com/tmc/langchaingo/exp/tools"
99
)
1010

11-
const Prefix = `Answer the following questions as best you can. You have access to the following Tools:`
12-
const FormatInstructions = `Use the following format:
11+
const (
12+
Prefix = `Answer the following questions as best you can. You have access to the following Tools:`
13+
FormatInstructions = `Use the following format:
1314
1415
Question: the input question you must answer
1516
Thought: you should always think about what to do
@@ -19,6 +20,7 @@ Observation: the result of the action
1920
... (this Thought/Action/Action Input/Observation can repeat N times)
2021
Thought: I now know the final answer
2122
Final Answer: the final answer to the original input question`
23+
)
2224
const Suffix = `Begin!
2325
2426
Question: {input}

exp/chains/stuff_documents_chain.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ var DefaultQAPrompt, _ = prompts.NewPromptTemplate(
5959
[]string{"context", "question"},
6060
)
6161

62-
// TODO: add conditional after chat model is added
62+
// TODO: add conditional after chat model is added.
6363
var QAPromptSelector = prompts.NewConditionalPromptSelector(DefaultQAPrompt, []prompts.Conditional{})
6464

6565
func loadQAStuffChain(llm llms.LLM) StuffDocumentsChain {

exp/doc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
// Package exp constains experiemntal code that is subject to change or removal.
1+
// Package exp constains experimental code that is subject to change or removal.
22
// There are no compatibility guarantees for this package and its subpackages.
33
package exp

exp/document_loaders/document_loaders.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"github.com/tmc/langchaingo/schema"
66
)
77

8-
// Document loader is the interface for loading and splitting documents from a source
8+
// Document loader is the interface for loading and splitting documents from a source.
99
type DocumentLoader interface {
1010
// Loads from source and returns documents
1111
Load() ([]schema.Document, error)

exp/document_loaders/text_loader.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
type TextLoader struct {
1111
filePath string
12-
//Todo: blob equivalent
12+
// Todo: blob equivalent
1313
}
1414

1515
func NewTextLoaderFromFile(filePath string) TextLoader {

exp/embeddings/embeddings.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package embeddings
22

3-
// Embeddings is the interface for creating vector embeddings from texts
3+
// Embeddings is the interface for creating vector embeddings from texts.
44
type Embeddings interface {
55
// Returns vector for each text
66
EmbedDocuments(texts []string) ([][]float64, error)

exp/memory/chat_memory.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ func (h *ChatMessageHistory) GetMessages() []schema.ChatMessage { return h.messa
1010
func (h *ChatMessageHistory) AddAiMessage(text string) {
1111
h.messages = append(h.messages, schema.AIChatMessage{Text: text})
1212
}
13+
1314
func (h *ChatMessageHistory) AddUserMessage(text string) {
1415
h.messages = append(h.messages, schema.HumanChatMessage{Text: text})
1516
}
@@ -28,7 +29,7 @@ func NewChatMessageHistory(options ...NewChatMessageOption) *ChatMessageHistory
2829

2930
type NewChatMessageOption func(m *ChatMessageHistory)
3031

31-
// Option for NewChatMessageHistory adding previous messages to the history
32+
// Option for NewChatMessageHistory adding previous messages to the history.
3233
func WithPreviousMessages(previousMessages []schema.ChatMessage) NewChatMessageOption {
3334
return func(m *ChatMessageHistory) {
3435
m.messages = append(m.messages, previousMessages...)

exp/memory/memory.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,24 @@ func getBufferString(messages []schema.ChatMessage, humanPrefix, aiPrefix string
5252
role = humanPrefix
5353
default:
5454
role = string(message.GetType())
55-
5655
}
5756

5857
stringMessages = append(stringMessages, fmt.Sprintf("%s: %s", role, messages[i].GetText()))
5958
}
6059

61-
return strings.Join(stringMessages[:], "\n")
60+
return strings.Join(stringMessages, "\n")
6261
}
6362

6463
type EmptyMemory struct{}
6564

6665
func (m EmptyMemory) MemoryVariables() []string {
6766
return []string{}
6867
}
68+
6969
func (m EmptyMemory) LoadMemoryVariables(map[string]any) map[string]any {
7070
return map[string]any{}
7171
}
72+
7273
func (m EmptyMemory) SaveContext(inputs map[string]any, outputs map[string]any) error {
7374
return nil
7475
}

exp/output_parsers/empty_parser.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package output_parsers
22

33
import "github.com/tmc/langchaingo/exp/prompts"
44

5-
// Output parser that does nothing
5+
// Output parser that does nothing.
66
type EmptyOutputParser struct{}
77

88
func (p EmptyOutputParser) GetFormatInstructions() string { return "" }

exp/prompts/chat_template.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,14 @@ type ChatPromptValue struct {
151151
messages []schema.ChatMessage
152152
}
153153

154-
// Formats the ChatPromptValue as a JSON string
154+
// Formats the ChatPromptValue as a JSON string.
155155
func (v ChatPromptValue) String() string {
156-
157156
keyValueJSON := make([]string, 0)
158157
for i := 0; i < len(v.messages); i++ {
159158
keyValueJSON = append(keyValueJSON, fmt.Sprintf("{\"text\":\"%s\"}", v.messages[i].GetText()))
160159
}
161160

162-
return fmt.Sprintf("[%s]", strings.Join(keyValueJSON, ",")) //Joins the string with [] around creating an array of objects
161+
163162
}
164163

165164
func (v ChatPromptValue) ToChatMessages() []schema.ChatMessage {

exp/prompts/chat_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ func TestChatTemplate(t *testing.T) {
5858
// use cmp to compare:
5959
if !cmp.Equal(chatMessages.ToChatMessages(), expectedChatMessages) {
6060
t.Errorf("Chat template format prompt value chat messages not equal to expected. Diff: %s", cmp.Diff(chatMessages.ToChatMessages(), expectedChatMessages))
61-
6261
}
6362

6463
if !(chatMessages.String() == expectedString) {

exp/prompts/template.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,17 @@ func renderTemplate(template string, templateFormat string, inputValues map[stri
3131
return formatter(template, inputValues)
3232
}
3333

34-
type parsedFStringNode interface{}
35-
type fStringLiteral struct{ text string }
36-
type fStringVariable struct{ name string }
34+
type (
35+
parsedFStringNode interface{}
36+
fStringLiteral struct{ text string }
37+
fStringVariable struct{ name string }
38+
)
3739

3840
func paresFString(_template string) ([]parsedFStringNode, error) {
3941
template := []rune(_template)
4042
nodes := make([]parsedFStringNode, 0)
4143

4244
for i := 0; i < len(template); {
43-
4445
if template[i] == '{' && i+1 < len(template) && template[i+1] == '{' {
4546
nodes = append(nodes, fStringLiteral{text: "{"})
4647
i += 2
@@ -115,7 +116,6 @@ func interpolateFString(template string, values map[string]any) (string, error)
115116
output += fmt.Sprintf("%v", variableValue)
116117
case fStringLiteral:
117118
output += n.text
118-
119119
}
120120
}
121121

exp/text_splitters/recursive_character.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ func NewRecursiveCharactersSplitter() RecursiveCharactersSplitter {
1919
}
2020

2121
func (s RecursiveCharactersSplitter) SplitText(text string) ([]string, error) {
22-
23-
//Find the appropriate separator
22+
// Find the appropriate separator
2423
separator := s.Separators[len(s.Separators)-1]
2524
for _, s := range s.Separators {
2625
if s == "" {
@@ -34,15 +33,14 @@ func (s RecursiveCharactersSplitter) SplitText(text string) ([]string, error) {
3433
}
3534
}
3635

37-
//Split the text
36+
3837
splits := strings.Split(text, separator)
3938

40-
//Merge
39+
4140
finalChunks := make([]string, 0)
4241
goodSplits := make([]string, 0)
4342

4443
for _, split := range splits {
45-
4644
if len(split) < s.ChunkSize {
4745
goodSplits = append(goodSplits, split)
4846
continue

exp/text_splitters/recursive_character_test.go

-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ type test struct {
1616

1717
var tests = []test{
1818
{
19-
2019
text: "Hi.\nI'm Harrison.\n\nHow?\na\nb",
2120
chunkOverlap: 1,
2221
chunkSize: 20,
@@ -42,7 +41,6 @@ var tests = []test{
4241
},
4342
},
4443
{
45-
4644
text: "Hi.\nI'm Harrison.\n\nHow?\na\nbHi.\nI'm Harrison.\n\nHow?\na\nb",
4745
chunkOverlap: 1,
4846
chunkSize: 40,
@@ -85,5 +83,4 @@ func TestRecursiveCharacterSplitter(t *testing.T) {
8583
t.Logf("Result creating documents with recursive character splitter not equal expected. \n Got:\n %v \nWant:\n %v \n", docs, test.expectedDocs)
8684
}
8785
}
88-
8986
}

exp/text_splitters/text_spliters.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type LOCMetadata struct {
3232
Lines LineData
3333
}
3434

35-
// Creates documents with a text splitter
35+
// Creates documents with a text splitter.
3636
func CreateDocuments(textSplitter TextSplitter, texts []string, metadatas []map[string]any) ([]schema.Document, error) {
3737
if len(metadatas) == 0 {
3838
metadatas = make([]map[string]any, len(texts))
@@ -56,12 +56,11 @@ func CreateDocuments(textSplitter TextSplitter, texts []string, metadatas []map[
5656
}
5757

5858
for _, chunk := range chunks {
59-
6059
// Code for adding line number to the metadata of the chunk.
6160
// Does not work because some chunks generated are very small and can be written multiple places in the file
6261
// Makes it impossible to find the correct index
6362

64-
//Find complete number of newlines between last chunk and current chunk
63+
// Find complete number of newlines between last chunk and current chunk
6564
/* numberOfIntermediateNewLines := 0
6665
if !first {
6766
prevIndexChunk := strings.Index(text, prevChunk)
@@ -142,7 +141,6 @@ func MergeSplits(splits []string, separator string, chunkSize int, chunkOverlap
142141

143142
doc := joinDocs(currentDoc, separator)
144143
if doc != "" {
145-
146144
docs = append(docs, doc)
147145
}
148146

exp/tools/serpapi/internal/serpapi_client.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import (
1212
"strings"
1313
)
1414

15-
var ErrMissingToken = errors.New("missing the OpenAI API key, set it in the SERPAPI_API_KEY environment variable")
16-
var NoGoodResult = "No good search result found"
15+
var (
16+
ErrMissingToken = errors.New("missing the OpenAI API key, set it in the SERPAPI_API_KEY environment variable")
17+
NoGoodResult = "No good search result found"
18+
)
1719

1820
type SerpapiClient struct {
1921
apiKey string

exp/tools/serpapi/serpapi_tool.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/tmc/langchaingo/exp/tools/serpapi/internal"
88
)
99

10-
//Create a new tool for serpapi to search on internet
10+
// Create a new tool for serpapi to search on internet.
1111
func New() (*tools.Tool, error) {
1212
client, err := internal.New()
1313
if err != nil {
@@ -30,5 +30,4 @@ func New() (*tools.Tool, error) {
3030
return strings.Join(strings.Fields(result), " "), nil
3131
},
3232
}, nil
33-
3433
}

exp/tools/tool.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Package tools defines the types for tools to be used by the llms agents.
22
package tools
33

4-
// Tool is a tool for the llm agent to interact with diferent application.
4+
// Tool is a tool for the llm agent to interact with different application.
55
type Tool struct {
66
Name string
77
Description string

0 commit comments

Comments
 (0)