-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from stoerr/feature/pseudomodels
- Loading branch information
Showing
7 changed files
with
156 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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
80 changes: 80 additions & 0 deletions
80
...src/main/java/net/stoerr/ai/aigenpipeline/framework/chat/CopyPseudoAIChatBuilderImpl.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package net.stoerr.ai.aigenpipeline.framework.chat; | ||
|
||
/** | ||
* A pseudo AI chat model that just copies the input to the output. | ||
*/ | ||
public class CopyPseudoAIChatBuilderImpl implements AIChatBuilder { | ||
|
||
/** | ||
* Pseudo model that just concatenates the inputs and writes these to the output. | ||
*/ | ||
public static final String MODEL_COPY = "copy"; | ||
|
||
protected final StringBuilder allInputs = new StringBuilder(); | ||
|
||
@Override | ||
public AIChatBuilder url(String url) { | ||
// not used | ||
return this; | ||
} | ||
|
||
@Override | ||
public AIChatBuilder key(String key) { | ||
// not used | ||
return this; | ||
} | ||
|
||
@Override | ||
public AIChatBuilder organizationId(String organizationId) { | ||
// not used | ||
return this; | ||
} | ||
|
||
@Override | ||
public AIChatBuilder maxTokens(int maxTokens) { | ||
// not used | ||
return this; | ||
} | ||
|
||
@Override | ||
public AIChatBuilder model(String model) { | ||
if (!MODEL_COPY.equals(model)) { | ||
throw new IllegalArgumentException("Only model " + MODEL_COPY + " is supported."); | ||
} | ||
return this; | ||
} | ||
|
||
@Override | ||
public AIChatBuilder systemMsg(String text) { | ||
// not used | ||
return this; | ||
} | ||
|
||
@Override | ||
public AIChatBuilder userMsg(String text) { | ||
// not used | ||
return this; | ||
} | ||
|
||
/** | ||
* We assume the "put it into the mouth of the AI" pattern is used. Then all the assistant messages are actually | ||
* the inputs. (That is a bit dangerous if it's used differently, but the easiest way.) | ||
*/ | ||
@Override | ||
public AIChatBuilder assistantMsg(String text) { | ||
if (text != null) { | ||
allInputs.append(text); | ||
} | ||
return this; | ||
} | ||
|
||
@Override | ||
public String toJson() { | ||
return allInputs.toString(); | ||
} | ||
|
||
@Override | ||
public String execute() { | ||
return allInputs.toString(); | ||
} | ||
} |
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!-- AIGenPromptStart(copydata) | ||
This uses the copy fake model to just copy the data.txt file. | ||
AIGenCommand(copydata) | ||
-m copy -wo -f data.txt | ||
AIGenPromptEnd(copydata) --> | ||
Name: Franz | ||
Profession: Frontend developer | ||
|
||
Name: Karl | ||
Profession: Backend developer | ||
|
||
Name: Maria | ||
Profession: Designer | ||
<!-- AIGenEnd(copydata) --> | ||
|
||
<!-- AIGenPromptStart(openaijson) | ||
This uses the openaijson fake model to just insert the JSON that would have been sent to OpenAI into the file. | ||
AIGenCommand(openaijson) | ||
-m openaijson -wo -f data.txt | ||
AIGenPromptEnd(openaijson) --> | ||
{ | ||
"model": "openaijson", | ||
"messages": [ | ||
{ | ||
"role": "system", | ||
"content": "You are an expert programming assistant who follows the users instructions exactly and to the letter.\nYou observe the rules of clean code, KISS, YAGNI, and DRY and love good documentation and well documented code.\nDo never ever give any introductory or concluding text, just the requested output, except if explicitly asked for.\n\nIMPORTANT: If something in the instructions is unclear, there is information missing, you have any questions\nor after printing the response you notice that something was wrong, then append to the file a paragraph starting with\n`FIXME(GenAIPipeline) ` and a description of that problem.\n" | ||
}, | ||
{ | ||
"role": "user", | ||
"content": "Retrieve the content of the input file 'data.txt'" | ||
}, | ||
{ | ||
"role": "assistant", | ||
"content": "Name: Franz\nProfession: Frontend developer\n\nName: Karl\nProfession: Backend developer\n\nName: Maria\nProfession: Designer\n" | ||
}, | ||
{ | ||
"role": "user", | ||
"content": "This uses the copy fake model to just copy the data.txt file. \n" | ||
} | ||
], | ||
"temperature": 0.0, | ||
"max_tokens": 2048 | ||
} |
This file contains 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