Skip to content

Commit

Permalink
feat: update sample
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotzh committed Sep 28, 2023
1 parent 3cb3578 commit 930e076
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 32 deletions.
22 changes: 8 additions & 14 deletions src/PromptflowCSharp/Flow2/Flow2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,16 @@ public Flow2()

}

[PromptFlow.Tool]
public static String CallSimpleLLM(String prompt)
{
Console.WriteLine("Call simple inline LLM with prompt " + prompt);
return prompt;
}

public Output Execute(Input inputs)
{
var out1 = CallSimpleLLM(inputs.Prompt);
var out2 = SampleTool.SimpleLLM.CallSimpleLLM(out1 as string);
return new Output()
{
Out1 = out1,
Out2 = out2,
};
var output = new Output();
// execution code: start
var node1 = InternalTool.CallSimpleLLM(inputs.Prompt);
var node2 = SampleTool.SimpleLLM.CallSimpleLLM(node1);
output.Out1 = node1;
output.Out2 = node2;
// execution code: end
return output;
}
}
}
19 changes: 19 additions & 0 deletions src/PromptflowCSharp/Flow2/InternalTool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Flow
{
internal class InternalTool
{
[PromptFlow.Tool]
public static String CallSimpleLLM(String prompt)
{
Console.WriteLine("Call simple internal LLM with prompt " + prompt);
return "Internal Processed " + prompt;
}

}
}
18 changes: 2 additions & 16 deletions src/PromptflowCSharp/Flow2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,9 @@

var flow = new Flow2();

flow.Execute(new Flow2.Input() { Prompt = "test input prompt" });
var output = flow.Execute(new Flow2.Input() { Prompt = "test input prompt" });

var function = flow.Execute;
var body = function.GetMethodInfo().GetMethodBody();
Console.WriteLine($"Executed flow with output:\nOut1: {output.Out1}\nOut2: {output.Out2}");

SyntaxTree tree = CSharpSyntaxTree.ParseText("../../../Flow2.cs");
CompilationUnitSyntax root = tree.GetCompilationUnitRoot();
var nodes = root.DescendantNodes().ToList();
var property = root.DescendantNodes()
.OfType<MethodDeclarationSyntax>()
.Where(md => md.Identifier.ValueText.Equals("Execute"))
.FirstOrDefault();
var compilation = CSharpCompilation.Create("HelloWorld")
.AddReferences(MetadataReference.CreateFromFile(
typeof(string).Assembly.Location))
.AddSyntaxTrees(tree);
Parser parser = new Parser();
parser.Generate("../../../Temp.cs");

Console.WriteLine();
2 changes: 1 addition & 1 deletion src/PromptflowCSharp/Flow2/Temp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// </auto-generated>
//------------------------------------------------------------------------------

namespace CodeDOMSample
namespace Flow
{
using System;

Expand Down
2 changes: 1 addition & 1 deletion src/PromptflowCSharp/SampleTool/SimpleLLM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class SimpleLLM
public static String CallSimpleLLM(String prompt)
{
Console.WriteLine("Call standalone simple LLM with prompt " + prompt);
return prompt;
return "External Processed " + prompt;
}
}
}

0 comments on commit 930e076

Please sign in to comment.