-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'XiaoMi:multi_agent' into multi_agent
- Loading branch information
Showing
18 changed files
with
633 additions
and
132 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
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
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 |
---|---|---|
|
@@ -3,6 +3,14 @@ | |
import com.google.common.collect.ImmutableMap; | ||
import run.mone.hive.actions.WriteCode; | ||
import run.mone.hive.common.AiTemplate; | ||
import run.mone.hive.common.StreamingXmlParser; | ||
import run.mone.hive.common.XmlParserCallbackAdapter; | ||
import run.mone.hive.schema.Message; | ||
import run.mone.hive.schema.MetaKey; | ||
import run.mone.hive.schema.MetaValue; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author [email protected] | ||
|
@@ -15,25 +23,46 @@ public class WritePythonCode extends WriteCode { | |
${requirements} | ||
Please provide only the function implementation without any additional explanations. Wrap the code in <code></code> tags. | ||
Please provide only the function implementation without any additional explanations. Wrap the code in <boltAction></boltAction> tags. | ||
Here's an example of a sum function: | ||
<code> | ||
<boltAction> | ||
def execute(params): | ||
a = params.get('a', 0) | ||
b = params.get('b', 0) | ||
return a + b | ||
</code> | ||
</boltAction> | ||
Now, please implement the function based on the given requirements. | ||
"""; | ||
|
||
public WritePythonCode() { | ||
setName("WritePythonCode"); | ||
setDescription(""); | ||
setFunction((req, action) -> { | ||
String message = req.getMessage().getContent(); | ||
String str = AiTemplate.renderTemplate(prompt, ImmutableMap.of("requirements", message)); | ||
return this.llm.chat(str); | ||
List<String> codeList = new ArrayList<>(); | ||
StringBuilder sb = new StringBuilder(); | ||
new StreamingXmlParser(new XmlParserCallbackAdapter() { | ||
@Override | ||
public void onActionStart(String type, String subType, String filePath) { | ||
sb.setLength(0); | ||
} | ||
|
||
@Override | ||
public void onActionEnd() { | ||
codeList.add(sb.toString()); | ||
sb.setLength(0); | ||
} | ||
|
||
@Override | ||
public void onContentChar(char c) { | ||
sb.append(c); | ||
} | ||
}).append(str); | ||
return Message.builder().content(this.llm.chat(str)).meta(ImmutableMap.of(MetaKey.builder().key("code").build(), MetaValue.builder().value(codeList).build())).build(); | ||
}); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
jcommon/hive/src/main/java/run/mone/hive/common/CustomStreamTag.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,45 @@ | ||
package run.mone.hive.common; | ||
|
||
import java.util.Arrays; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* @author [email protected] | ||
* @date 11/25/24 4:00 PM | ||
*/ | ||
public enum CustomStreamTag { | ||
|
||
UNKNOWN(0, "unknown"), | ||
ACTION(1, "boltAction"), | ||
ARTIFACT(2, "boltArtifact"); | ||
|
||
private final int code; | ||
private final String tagName; | ||
|
||
private static final Map<Integer, CustomStreamTag> valMap = Arrays.stream(values()).collect(Collectors.toMap(CustomStreamTag::getCode, Function.identity())); | ||
|
||
private static final Map<String, CustomStreamTag> nameMap = Arrays.stream(values()).collect(Collectors.toMap(CustomStreamTag::getTagName, Function.identity())); | ||
|
||
CustomStreamTag(int code, String tagName) { | ||
this.code = code; | ||
this.tagName = tagName; | ||
} | ||
|
||
public int getCode() { | ||
return code; | ||
} | ||
|
||
public String getTagName() { | ||
return tagName; | ||
} | ||
|
||
public static CustomStreamTag getTagByName(String tagName) { | ||
return nameMap.getOrDefault(tagName, UNKNOWN); | ||
} | ||
|
||
public static boolean isValidTagName(String tagName) { | ||
return !UNKNOWN.getTagName().equals(tagName) && nameMap.containsKey(tagName); | ||
} | ||
} |
Oops, something went wrong.